FileUpload component script help

Hi i am new to scripting and am struggling to save an image.

I have a simple form which logs users input values from dropdowns into a SQL database when the user clicks the “Submit” button. I would like to additionally have the user take a picture(using FileUpload Component) and log it to the database with all the other values they have input.

I have managed to get the image to upload to the database using the onFileRecieved but I actually want it to be submitted when the user selects the “Submit” button. Any help appreciated


Hi Craig,

One way we do this is onFileRecieved, save the file to disk with a uniquely generated id.

Then on the submit button we read the file from disk (system.file.readFileAsBytes) and stick it in the database as a BASE64 encoded blob.

@Craighunter1986, you’re using the right technique. You wouldn’t have access to the image/picture to save to the DB until you get it via the onFileRecieved event.

Thanks Jonathan and @jball .

I used the onFileRecieved to upload to webserver/webapps/main/ using event.file.copyTo(). I kept the filename the same (each new upload overwrites the previous) so when I select the button I was able to reference the filename I wanted. Since the database write script was taking place on the button I wasn’t sure how to reference an everchanging filename variable that was created on the fileUpload component and also I didn’t want to accumulate a load of pictures in the webserver folder.

This worked on my test system on my laptop but when I went to try it on the server I get the following error:

Error running action ‘dom.onClick’ on picturetest@D/root/Button: Traceback (most recent call last): File " ", line 4, in runAction IOError: File ‘webserver/webapps/main/TestPicture1’ doesn’t exist or isn’t a file.

The picture isn’t being located in the Webserver folder. I don’t have direct access to the install folders on the server unlike my test system so will need to speak to IT to see if the file is being generated from the onFileRecieved and if not why not.

Probably an issue (permissions, file path, etc) with the write to your file storage location from event.file.copyTo. If onFileRecieved is firing, you’ve definitely got the file at that point.