NetTalk Central

Author Topic: Where can I process file and folder name prior to upload?  (Read 6520 times)

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Where can I process file and folder name prior to upload?
« on: September 17, 2012, 06:36:19 AM »
Currently I am creating (if not existing already) an upload folder for each user after successful login to secwin.  I allow them to upload a certificate of completion and need to do some processing such as delete old certificate, assign values to other fields and rename to file to make sure it goes to the individual's folder.

Which embed should I use for this?

Thanks.

  RJ

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #1 on: September 17, 2012, 10:52:29 AM »
Bruce... I have gotten this to work but I don't think it is working the way you probably intended.

The p_web.rename() in webhandler has the third parameter p_path as optional and I expect is not being passed from the netwebform I am using so attempts to modify p_path do not generate an error but also do not result in assignment.  If you declare a p_path string in this virtual function it works but generates a duplicate warning.

Also...  if you declare a user upload path consistent with default assignment given to p_web.site.uploadspath (no trailing '\') the rename results in a file in uploads whose name is final substring of p_path concatenated with p_filename... since it does work properly normally I assume a '\' is being concatenated somewhere prior to the call to p_web.rename() from your code.

And... if another procedure needs to modify p_path in some other way I expect it will break without rethinking this code again.

Sorry if this sounds like I had too much beer again...

  RJ

Anyway... works but sort of clunky

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: Where can I process file and folder name prior to upload?
« Reply #2 on: September 18, 2012, 05:26:52 AM »
there is a bug in 6.44 with upload paths, so perhaps we should revisit this when I've shipped, and you have, 6.45.

No, you shouldn't declare, or alter, the p_path parameter.
You should (if you want to change the path) declare a local variable, say, loc:path, and use that in the parent call instead of the p_path parameter.

cheers
Bruce

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #3 on: September 18, 2012, 06:57:09 AM »
Not sure I understand.  What I have done is modify the code in handler virtual function.  The parent.rename() is generated so cannot be modified.  I could make the call myself and do an "omit" around the existing generated code but this would have to be maintained and make it less than "capesoft std".

Should I be calling p_web.rename() from the netwebform with a local?  If so where should this call be?  Does seem like a better idea to do it in the netwebform as each netwebform could do it's own thing that way without logic being shared.  What I am in process of doing now is setting up a session variable such that the p_web.rename() can tell who called and act on that information in the virtual.  This just seems like the wrong way to go about it but not sure how else to do it.

Thanks.

  RJ

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: Where can I process file and folder name prior to upload?
« Reply #4 on: September 18, 2012, 07:39:25 AM »
>> The parent.rename() is generated so cannot be modified.

yes. standard practice in this case is to code in the parent call yourself (ie copy it from the Generated code) and then put a RETURN after it (so the generated one is not called.)

>> Should I be calling p_web.rename() from the netwebform with a local?

no, it's called by the engine as the file arrives.

>> Does seem like a better idea to do it in the netwebform as each netwebform could do it's own thing that way without logic being shared.

yes, of course. And of course you can actually rename the file anytime you like, using the standard Clarion "RENAME" command. The reason there's a "hook" to do it earlier is because it's potentially possible for 2 users to upload files with the same name, at the same time. In other words the WebHandler lets you set the name _before_ it gets written to disk whereas the form can only change the name of the file on the disk.

>> What I am in process of doing now is setting up a session variable such that the p_web.rename() can tell who called and act on that information in the virtual.

Currently in the WebHandler you don't know "which form this upload belongs to" - but what you do know is the "field name". So as long as your field name is reasonably unique you can make a good determination of what to do with the file. Your new name is then put into that field, so when it gets to the form it has the right name.

Cheers
Bruce


Cheers
Bruce

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #5 on: September 18, 2012, 08:33:49 AM »
Gotcha... thanks.

  RJ

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #6 on: September 26, 2012, 09:13:43 AM »
Bruce, I have 6.45 installed now and see that the results of file upload  is now relative to web folder.

Otherwise I don't see any change to what I have been working with.

If I use the file variable "ceu:certificate" as the target of the file-upload button then the variable is updated appropriately but no server-side code is executed and the resets do not result in redisplay of fields modified with p_web.ssv in the web handler rename method.  I have noticed that in a "normal" button the server-side code is executed.  Would I do better to use a normal button and try and generate the file-upload in some other way?

The main reason for this file processing is that there can be only one certificate of completion per course so if they upload again it needs to delete the old one as you cannot assume that the new one will be the same name... probably scanned or image from a camera phone.

Thanks.

  RJ

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #7 on: September 26, 2012, 10:49:35 AM »
Another thing...

File upload works with IE but not with chrome or firefox.  The filename box just fllashes and goes blank in firefox and chrome.  Downloads work on all of them.

  RJ

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: Where can I process file and folder name prior to upload?
« Reply #8 on: September 27, 2012, 12:18:15 AM »
Hi Rick,

I think it's worth pointing out that the file only uploads when the Form is completed. There's nothing you can usefully do when the file is selected, so it doesn't run any server code at this point, and the file is not sent at this point.

The code we have been discussing in the web handler only runs when the form is submitted (ie the user clicks on Save).

>> probably scanned or image from a camera phone.

be aware that iOs in particular does not support the File Upload field at all, so you can't use this approach to get photos off an iOS device.

cheers
Bruce

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #9 on: September 27, 2012, 02:19:50 AM »
Could any of its routines be running on exit from the form and restoring the value after I set it to '' ?

  RJ

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11239
    • View Profile
Re: Where can I process file and folder name prior to upload?
« Reply #10 on: September 27, 2012, 05:08:05 AM »
I think maybe you need to modify the File Upload example to show the effect you are getting Rick.
File Uploads are complex, and I'm not sure I understand all the flow that you are doing.

cheers
Bruce

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #11 on: September 27, 2012, 07:59:55 AM »
Good idea... will try that.  Also a good way to see if Chrome and Firefox objecting to me or nettalk :)

  RJ

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #12 on: September 27, 2012, 09:04:11 AM »
In the file upload example most of the activity takes place in the complete form start embed and uses the value queue.  Also all three browsers work properly with slightly different UI elements.

Mine does most of the processing in the handler rename method and I use the session queue exclusively and only IE functions properly.  Why are you using the value queue instead of session queue?  I looked it up in the nettalk book but has very little about the value queue other then it is pertaining to passed parameters to browser (or from browser?).

When is the complete form embed called?  When getting ready to return to browse?

I was also trying to force a field to update... the field being used by the file upload button... it is VERY RESISTANT to that.  Almost like I don't really have access to that field like the others.

Thanks.

  RJ

rjmiller

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: Where can I process file and folder name prior to upload?
« Reply #13 on: September 27, 2012, 11:43:05 AM »
Bruce:

If I put the following code in the file upload example in the complete form code start embed... p_web.ssv('MAI:MailBoxPicture','') the file does not get updated with this "null" value.  This is what I have been fighting with in my application... I cannot clear this field.

  RJ