Tools
Sign in
Login
Forum
Understanding File Upload
Forum
>
Ask Anything
>
Understanding File Upload
Krishan Agarwal
posted
on July 2, 2013
at 11:59 AM
Krishan Agarwal
posted
on July 2, 2013
at 11:59 AM
Hi,
Want to understand the File upload functionality a little better. So, I walk through the steps and then ask my question:
Step 1 : Add File Upload component. User can click on it and select a file from its desktop.
Step 2 : Add a button and add a script action to it.
Now my question:
I do not see any code in the script action, so not sure how the file is getting moved to the server and the binded dataclass is updated?
Thanks & Regards
Krishan
Lukas Mathis
replied
on July 2, 2013
at 12:18 PM
Lukas Mathis
replied
on July 2, 2013
at 12:18 PM
You got the first two things right: you need a File Upload Component, and a Button that submits the Screen, and triggers the upload.
The next thing you need to do is to add a variable that is bound to the File Upload Component (type String in older versions of Appway, and HttpFileUpload in newer versions). I'll call that variable $file. This will contain the path of the uploaded file if it's a String, or additional metadata if it's of type HttpFileUpload.
(If your Appway version supports HttpFileUpload, use this, as it makes it easier to get the uploaded file's original name, and other data.)
The Action you add to the button should be a Script Action. In there, you decide what to do with the uploaded file. Here's an example for such a Script:
1
Script
2
If FILEEXISTS($file) Then
3
// do something with the file here
4
End
5
End
In other words, you need to move the file to wherever you want it to be stored with your Script.
Krishan Agarwal
replied
on July 2, 2013
at 12:23 PM
Krishan Agarwal
replied
on July 2, 2013
at 12:23 PM
Yep - but this script should be run after the file is safely stored in the server in some tmp directory.
How does the files goes to the server and get stored in a particular tmp directory.
Thanks - Krish
Lukas Mathis
replied
on July 2, 2013
at 12:33 PM
Lukas Mathis
replied
on July 2, 2013
at 12:33 PM
The file is uploaded automatically when the page is submitted. You shouldn't have to worry about that, Appway will take care of it.
n/A
replied
on July 2, 2013
at 1:13 PM
n/A
replied
on July 2, 2013
at 1:13 PM
Krishan,
The fileUpload screen component renders as a:
1
< input class="FileUpload discreteComponent" type="file" name="xxxx" / >
in the generated HTML page.
This means that whenever the page is submitted, if the user selects a file this is sent together with the page request. Same as an input field, if it is filled in it gets submitted by the browser as a parameter.
Appway handles this submission by storing the file in a temp folder in the /work folder, but as Lukas was saying you should not handle that "manually". The binding to an HttpFileUpload object gives you the handler you need to eventually move the file to another folder (where you want to keep it), read it for display (e.g. a PDF) and so on.
Krishan Agarwal
replied
on July 2, 2013
at 1:17 PM
Krishan Agarwal
replied
on July 2, 2013
at 1:17 PM
Thanks Mauro, Thanks Lukas - that answers my question.
Please
sign in
to add a reply
About this site
|
Terms of use
|
Privacy statement
|
Contact us
© 2025 Appway AG. All Rights Reserved.
Want to understand the File upload functionality a little better. So, I walk through the steps and then ask my question:
Step 1 : Add File Upload component. User can click on it and select a file from its desktop.
Step 2 : Add a button and add a script action to it.
Now my question:
I do not see any code in the script action, so not sure how the file is getting moved to the server and the binded dataclass is updated?
Thanks & Regards
Krishan