Login ProductsSalesSupportDownloadsAbout |
Home » Technical Support » Elevate Web Builder Technical Support » Support Forums » Elevate Web Builder 2 Preview » View Thread |
Messages 1 to 10 of 12 total |
How do I read a local file, so I can upload it? |
Mon, Jun 15 2015 7:21 PM | Permanent Link |
Doug B | I've scoured the forums and documentation, and while I have seen many references to the file upload picker, I haven't seen any examples of actually reading the contents of a local file, so it can be sent via the TServerRequest component.
I have a custom back-end server that will accept binary data from a POST, but I don't know how to load the file into memory using EWB 2, so I can get the actual data to send. Any help would be greatly appreciated. Thanks, Doug |
Mon, Jun 15 2015 8:29 PM | Permanent Link |
Doug B | Ok, I figured out how to do this and it works with a file in the 'output' directory, but if I use a file from another path I get an 'access denied' error. I understand the restrictions of cross domain requests, but the path below works as-is in my local browser, and I've used other apps on the web that let me access the same file in the example below.
procedure TMyForm.OnFileLoaded(aRequest: TServerRequest); var Data: string; begin if (aRequest.StatusCode <> 200) then Window.Alert('Upload Failed') else Window.Alert('Upload Succeded'); Data := aRequest.ResponseContent.Text; Window.Alert(Data); end; procedure TMyForm.UploadFile; begin // fServerRequest.Url := 'import.txt'; <---------------- THIS WORKS fServerRequest.Url := 'file:///c:/temp/import.txt'; <---------- ACCESS DENIED ERROR fServerRequest.OnComplete := OnFileLoaded; fServerRequest.Execute; end; What am I doing wrong here? Thanks, Doug |
Tue, Jun 16 2015 4:21 AM | Permanent Link |
Mark Brooks Slikware | Doug B wrote:
>>I've scoured the forums and documentation, and while I have seen many references to the file upload picker, I >>haven't seen any examples of actually reading the contents of a local file, so it can be sent via the TServerRequest >>component. Hi Doug, As I understand it, the browser security restrictions will never let your JS directly access "local" files. That is the reason why a local path cannot be specified. Use the EWB FileUpload button or a 3rd party component, such as the JS MultiFileUploader for greater flexibility. These use the browser's inbuilt capabilities (enhanced in the HTML5 world). Mark |
Tue, Jun 16 2015 9:57 AM | Permanent Link |
Doug B | Mark,
I have the FileComboBox component, but don't see the FileUpload button in the component palette of EWB 2. I'll have to re-read the release notes, but perhaps it will be included after the initial release? Thanks, Doug Mark Brooks wrote: Doug B wrote: >>I've scoured the forums and documentation, and while I have seen many references to the file upload picker, I >>haven't seen any examples of actually reading the contents of a local file, so it can be sent via the TServerRequest >>component. Hi Doug, As I understand it, the browser security restrictions will never let your JS directly access "local" files. That is the reason why a local path cannot be specified. Use the EWB FileUpload button or a 3rd party component, such as the JS MultiFileUploader for greater flexibility. These use the browser's inbuilt capabilities (enhanced in the HTML5 world). Mark |
Tue, Jun 16 2015 11:26 AM | Permanent Link |
Raul Team Elevate | On 6/15/2015 7:21 PM, Doug B wrote:
> I've scoured the forums and documentation, and while I have seen many references to the file upload picker, I haven't seen any examples of actually reading the contents of a local file, so it can be sent via the TServerRequest component. > I have a custom back-end server that will accept binary data from a POST, but I don't know how to load the file into memory using EWB 2, so I can get the actual data to send. You cannot read a file and use httprequest (security issue - imaging any website being able to read any file on your PC !) but you can use the form submit upload capability : 1. drop a new THTMLForm component on your form (it defaults ot feMultiPartFormData encoding and POST so default settings are fine) 2. set the URL to your back-end server upload handler (i.e. http://<myserverip>/<myformsubmithandler>/ 3. drop a TFileComboBox ON the THTMLForm you have 4. drop a TButton ON the THTMLForm you have 5. in TButton click event call form submit (i.e. "HTMLForm1.Submit;") 6. run the project, click the browse button next to file combo to select file and the then press you button 7. data should show up as a post on your back-end web server Raul |
Tue, Jun 16 2015 10:59 PM | Permanent Link |
Doug B | Thanks, Raul.
Is there any way to intercept the data so that I can send it as a string to my back end web service via TServerRequest? I ask because my web service is expecting the format of the POST content to be formatted in a specific way. Doug Raul wrote: On 6/15/2015 7:21 PM, Doug B wrote: > I've scoured the forums and documentation, and while I have seen many references to the file upload picker, I haven't seen any examples of actually reading the contents of a local file, so it can be sent via the TServerRequest component. > I have a custom back-end server that will accept binary data from a POST, but I don't know how to load the file into memory using EWB 2, so I can get the actual data to send. You cannot read a file and use httprequest (security issue - imaging any website being able to read any file on your PC !) but you can use the form submit upload capability : 1. drop a new THTMLForm component on your form (it defaults ot feMultiPartFormData encoding and POST so default settings are fine) 2. set the URL to your back-end server upload handler (i.e. http://<myserverip>/<myformsubmithandler>/ 3. drop a TFileComboBox ON the THTMLForm you have 4. drop a TButton ON the THTMLForm you have 5. in TButton click event call form submit (i.e. "HTMLForm1.Submit;") 6. run the project, click the browse button next to file combo to select file and the then press you button 7. data should show up as a post on your back-end web server Raul |
Wed, Jun 17 2015 7:40 PM | Permanent Link |
Doug B | Raul,
The POST is working when sending to the correct URL via the method you provided, so thanks. However, if I post it to an incorrect URL and get a 400, I get a 'File Download - Security Warning' window in IE as shown in the attachment. This was unexpected, because I was doing a POST to upload the file, not download it. Is this expected? Also, is there an event that will be fired to let me know once the file has been successfully downloaded or if there has been an error? Thanks again, Doug Attachments: File Download Security Warning.png |
Wed, Jun 17 2015 10:14 PM | Permanent Link |
Raul Team Elevate | On 6/16/2015 10:59 PM, Doug B wrote:
> Is there any way to intercept the data so that I can send it as a string to my back end web service via TServerRequest? I ask because my web service is expecting the format of the POST content to be formatted in a specific way. I don't believe this capability is currently surfaced in EWB though it is possible at javascript level. Wrapping some external component/library might be easiest way for now if you need more control. I have not really had a need for file uploading so i know the basics but have not had a more in depth look into it. Raul |
Wed, Jun 17 2015 10:51 PM | Permanent Link |
Raul Team Elevate | On 6/17/2015 7:40 PM, Doug B wrote:
> The POST is working when sending to the correct URL via the method you provided, so thanks. > However, if I post it to an incorrect URL and get a 400, I get a 'File Download - Security Warning' window in IE as shown in the attachment. This was unexpected, because I was doing a POST to upload the file, not download it. > Is this expected? Also, is there an event that will be fired to let me know once the file has been successfully downloaded or if there has been an error? Not sure why your server responds with 400 (bad request ) for invalid URL (instead of 404) - unless it's a valid url but for some other purpose. However my first guess is that it's something specific to your web server and how it responds - easiest to troubleshoot is for you to use the browser debug tools to see the actual response coming back (see what content type and payload actually are - your server might be providing html error message or such that IE is trying to show you now). i can't easily replicate a 400 response at this time but i'm not able to duplicate the problem with IE and invalid URL (my server returns 404 though). Raul |
Thu, Jun 18 2015 1:03 PM | Permanent Link |
Doug B | Thanks, I will try to debug it.
Yeah, the 400 is what my web service is returning when an invalid/unrecognized URL is received. Doug Raul wrote: On 6/17/2015 7:40 PM, Doug B wrote: > The POST is working when sending to the correct URL via the method you provided, so thanks. > However, if I post it to an incorrect URL and get a 400, I get a 'File Download - Security Warning' window in IE as shown in the attachment. This was unexpected, because I was doing a POST to upload the file, not download it. > Is this expected? Also, is there an event that will be fired to let me know once the file has been successfully downloaded or if there has been an error? Not sure why your server responds with 400 (bad request ) for invalid URL (instead of 404) - unless it's a valid url but for some other purpose. However my first guess is that it's something specific to your web server and how it responds - easiest to troubleshoot is for you to use the browser debug tools to see the actual response coming back (see what content type and payload actually are - your server might be providing html error message or such that IE is trying to show you now). i can't easily replicate a 400 response at this time but i'm not able to duplicate the problem with IE and invalid URL (my server returns 404 though). Raul |
Page 1 of 2 | Next Page » | |
Jump to Page: 1 2 |
This web page was last updated on Monday, April 22, 2024 at 04:13 AM | Privacy PolicySite Map © 2024 Elevate Software, Inc. All Rights Reserved Questions or comments ? E-mail us at info@elevatesoft.com |