NetTalk Central
NetTalk Web Server => Web Server - Ask For Help => Topic started by: Keith on February 08, 2015, 12:37:37 AM
-
Hi
I am uploading photo files and changing the name to render them unique. I noticed (by inserting trace) that the code which saves the path and file name (SaveFile::FND:Photo1 Routine) executes three time for each upload. It looks as if the name is the same each time i.e I change it but on the second entry it is back to the original (the \web\uploads\<fname>.jpg) so there isn't any harm done.
But .. . is this anything to worry about and why is it happening (maybe I've done something wrong)?
Cheers
Keith
-
Hi Keith,
ha! I scoff at your prehistoric version. 8.32 is just sooo last year! :)
(There was a tweak in 8:33 - from the release notes;
Fix: Call to SaveFile removed from Validate routine (already in ValidateValue)
)
It should only be called 2 times, not 3 - once when the file is uploaded and once when the user clicks on the "Save" button. (In only 1 of the 2 cases will it actually do anything, but which time it actually saves depends on the uploader itself, and if you are storing in a file or a blob.)
Cheers
Bruce
-
Hi Bruce
Ok. I have upgraded to 8.34 and STheory 2.14 and it's better but no cigar >:(
What I have done is in the 'SaveFile::FND:Photo1 Routine' (my upload field is FND:Photo1) I am changing the name that is already loaded into FND:Photo1. I am successfully randomising the name and the new unique name is in FND:Photo1. So far so good.
BUT, as you said, the code still executes twice but my code also runs twice.
The first time the code runs I change the name of the file from Pet1.jpg (ignoring the path) to ABPet1.jpg and the second time that name gets changed to PPABPet1.jpg.
The file gets written to the \uploads folder as ABPet1.jpg but the name stored in the table is PPABPet1.jpg
On the File Upload field I just have 'Save file to uploads folder' ticked, no Blob, no 'Remove'. You said that in only one of the two cases will it do anything but this seems not to be the case.
Could we need an 8.35 :)
Cheers
Keith
-
Hi Bruce
The SaveFile code seems to be executed once after the upload and once on 'Save'.
I have fudged the result in the code by testing to see whether I have been there before and if so then doing nothing. So I now have code that works but its icky.
Any comments?
Thanks
Keith
-
hmm - I thought I replied to this thread, but obviously not...
The key is to wrap your code in a test to see if the file is actually included in the current request. (it may arrive as an async upload, it may arrive as part of the POST, so you should cope with it whenever it actually arrives.
The best thing to do is just check the GetValue;
l = self.GetValue(lower('fieldname_length')
where fieldname is the name of the file-upload field.
Cheers
Bruce
-
Bruce
Sorry I have to return to this but I'm stuck.
The code in SaveFile gets executed on 'Save' for the Form (as well as after an Upload) so, as you said, you have to decide whether to execute the 'change name' code or not.
But I don't know what:
l = self.GetValue(lower('fieldname_length')
means and got compile errors 'Field not found: GETVALUE' when I tried to nut out what it might be.
Could you spell out exactly what the 'test' is that goes around my code (which is just to execute a procedure).
Thanks
Keith
-
Sorry Keith, my mistake - I took that code from the netweb.clw and didn't adjust it for embedding. It should read p_web not self. ie
result = p_web.GetValue(lower('fieldname_length')) ! added missing bracket
you also need to declare result
result long
in the procedure, or routine, where it is used.
fieldName in this context is the fieldname of the field you are fiddling with. ie the fieldname of the file upload field. (if the fieldname and equate are different you _may_ need to use the equate - I haven't checked.)
Cheers
Bruce
-
Bruce
Not sure what I'm doing wrong here. I have got this line of code:
result = p_web.GetValue(lower('FND:Photo1_length')
FND:Photo1 is my Upload field name. The Equate is the same name.
I get the compile error:
'Expected: <operator> ), &={'
see attached pic.
Keith
[attachment deleted by admin]
-
looks like you are just missing a bracket off the end. Also I think the names of stored fields are case insensitive so you could lose the lower
p_web.GetValue('FND:Photo1_length')
-
Kevin
Ha! Missing a bracket indeed - and after all the drama . . . !
Of course you are right.
These file uploads work perfectly now after testing the 'result but this 'wrapper' code needs to go into the 'Developing Web Applications' book together with an explanation.
Cheers
Keith
-
Bruce et alia
Hi. There is one other point to report.
I had been doing all of this upload and file name change testing with action=change on the Form. After getting the name change working today I grafted the code into a Form which always starts in 'Insert' mode and the photo file name did not get changed ???
I found out that after the routine that creates the unique name is executed, for action=Insert, you have to set the photo name field session variable. For action=change you don't.
Without the p_web.ssv, in the 'insert' case the file gets uploaded to the \web\uploads folder with the correct (unique) name but the path name in the table field is the unchanged name.
Cheers
Keith