NetTalk Central

Author Topic: Upload File to Folder Outside of webfolder  (Read 3437 times)

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Upload File to Folder Outside of webfolder
« on: August 27, 2012, 05:24:47 PM »
I thought I had this working, but evidently not.  I want an uploaded photo to be saved into a folder outside of the webfolder.  I tried the code on page 89 of Bruce's book.  It only works inside the webfolder.

ReturnValue = Parent.RenameFile(p_name,p_filename,loc:path) -- where loc:path is MyImagePath.  Nada.

I tried: self.site.UploadsPath = MyImagePath  -- the problem here is that it blanks the filename in the Photo record.

I tried calling a procedure that does the copy from the WebUploads folder to MyImagePath.  Not working.

Is this possible? 

Thank you.

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Upload File to Folder Outside of webfolder
« Reply #1 on: August 27, 2012, 06:33:28 PM »
yes it does - have a look at the upload example and modify that to make it work like what you are trying to do. Use the _trace statements to debug.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: Upload File to Folder Outside of webfolder
« Reply #2 on: August 27, 2012, 09:50:08 PM »
Hi Jim,

So, the RenameFile method is the correct place.

>> ReturnValue = Parent.RenameFile(p_name,p_filename,loc:path) -- where loc:path is MyImagePath.  Nada.

I recommend putting debugging statements in here, perhaps just after the call, to determine what the values of ReturnValue and loc:Path are. Also make sure you do a RETURN before the parent call, otherwise ReturnValue will be overwritten.

You can also look at the code in netweb.clw, in the RenameFile method, to see what it is doing.

cheers
Bruce

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Upload File to Folder Outside of webfolder
« Reply #3 on: August 28, 2012, 04:08:46 AM »
Hi Kevin:  No luck with that outside of the webfolder. 

Bruce:  Trace is showing me that the variables are all correct for RenameFile.  I have a trace on ReturnValue -- which is NOTshowing up in the debug record at all.  I have it in the RenameFile embed -- before the parent call. I'm guessing that I don't have it in the right place.

Thank you.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: Upload File to Folder Outside of webfolder
« Reply #4 on: August 28, 2012, 09:17:38 PM »
Time to tweak the example to match what you have, and post it here Jim so we can. Clearly you're doing something wrong, and the fastest way to sort that out is to see what you are doing.

cheers
Bruce

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Upload File to Folder Outside of webfolder
« Reply #5 on: August 29, 2012, 04:06:45 AM »
Hi Bruce:  Thanks for your help.

I tweaked the FileUpload app.  Goal is to upload and display photos from specified path(which I hard-coded to save time).  Parent.RenameFile(p_name,p_filename,clip(loc:path)) -- works to save the photo to the correct folder.  The problem is that the Mai:MailBoxPicture field is not being saved, but is reverting to what it was prior to the update.

Sorry for the sloppy code. 

Best.

[attachment deleted by admin]

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Upload File to Folder Outside of webfolder -- Found Workaround
« Reply #6 on: August 30, 2012, 05:41:47 PM »
Hi Bruce: I found a way around this that serves my purposes even better.  I will write a separate app that gets started when the webserver loads -- and will pass the photo name, etc. from the webserver to my 2nd app.  That way, I can do some processing on the photo (check for size, run antivirus scan, etc before I move it into my photos folder) and won't tie up the webserver with those tasks.

Thanks again,

Jim

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Upload File to Folder Outside of webfolder
« Reply #7 on: August 30, 2012, 05:57:29 PM »
rather than having to maintain 2 apps why don't you just run the logic you have created in the 2nd app after the file is uploaded? It's already running on it's own thread so it should not affect the performance of the webserver too much.

Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Upload File to Folder Outside of webfolder
« Reply #8 on: August 30, 2012, 06:01:18 PM »
Hi Kevin:  I like your idea even better -- but I tried writing a procedure to do some of that and wasn't able to get it to work.  It's possible I didn't have the correct embed point and is probably worth looking at the option again.  I will give it another shot.

Thanks!

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11179
    • View Profile
Re: Upload File to Folder Outside of webfolder
« Reply #9 on: August 30, 2012, 09:58:36 PM »
Hi Jim,

while processing the image in a different process has some merit, it means you need to manage two apps, exes and so on. Yes, from a scalability point of view it means you can separate the process onto another machine, but unless you are getting scads of images coming in, I think this is likely to be overkill.

Ultimately of course the renaming should work - and you're free to do image processing on the WebHandler thread (_after_ you've sent the reply...). Or even spawn a new thread to process the image when the image arrives.

With regard to your example - it seemed to work here ok - at least as far as putting the file into the right folder goes. On my machine the incoming files did land in the c:\tss\photos folder.
That said, after commenting out your (unnecessary) embed code in the MailboxesFormControl procedure I noticed that the field value (ie what's being stored in the TPS file) is incorrect. So while the file exists in the appropriate folder, the pic does not display for downloading.

I tracked this bug to a folder-name-length problem. In the HandleFile method the filename is being changed (to remove the path part) and it's calculating the length of the path wrong. I have corrected that and the fix will be in 6.43.

cheers
Bruce




Jim A

  • Full Member
  • ***
  • Posts: 203
    • View Profile
    • Email
Re: Upload File to Folder Outside of webfolder
« Reply #10 on: August 31, 2012, 03:25:19 AM »
Thanks Bruce.  I appreciate it.  Will watch for 6.43.