Upload Remote Files in Web-Enabled Applications
At first, the file handling dual behavior in a Thinfinity® VirtualUI web-enabled application can appear to be a bit confusing for new developers and users who are accustomed to running the application from the desktop. It’s actually pretty simple, as you will see in this article.
Previously, we shared with you a brief summary of the file handling possibilities in Thinfinity® VirtualUI apps. In this opportunity, we will try to shed some light on this topic and show you how to upload remote files in web-enabled applications.
Getting Files from the Browser
A VirtualUI web-enabled application has the ability to open files from its application environment, as usual, by using the standard file system dialog. But if the developer sets VirtualUI.StdDialogs to false, when a user calls the application from the browser and wants to open a file, a special dialog box will appear to allow a file upload.
Why upload remote files and not open them?
When you use a web-enabled application from the browser, the communication is enabled through a server application: the Thinfinity® VirtualUI Server. In this way, you are actually using the app remotely, from the Web.
So, when you need to select a file located in the browser’s device to be read by the application, you need to do a file upload in order to send a file from the browser environment to the web-enabled application, which is running in the VirtualUI Server.
Activating the remote file mode
In order to activate the file upload, the developer has to set the VirtualUI.StdDialogs (for standard dialogs) attribute to false.
VirtualUI.StdDialogs := false;
To go back to using the standard Windows File Open dialog and do a common file open on the application machine or local network, the developer has to set this attribute to true. If you do this, the remote file upload will be deactivated.
Where is the uploaded file?
By default, the uploaded files are stored automatically in a public server folder (i.e. C:\Users\Public\Documents\Cybele Software\Thinfinity\VirtualUI\). Developers can retrieve uploaded files from this folder in order to handle them.
But if the developer wishes to use a different folder, Thinfinity® VirtualUI has additional ways to upload files to any other destination.
Changing the destination folder
The VirtualUI class has an event method called OnGetUploadDir which is fired during an upload request, allowing you to change the save folder.
This Delphi example shows how to define it:
procedure TMyForm.MyGetUploadDirHandler(Sender: TObject; var Directory: string; var Handled: Boolean); begin Handled := True; Directory := ExtractFilePath(Application.ExeName); End; ... ... VirtualUI.OnGetUploadDir := InternalGetUploadDir;
Another way to upload remote files
The VirtualUI class has an additional method to upload files from the browser. This method is:
Where virtualui is an instance of the VirtualUI class. This method allows you to upload files from browsers and store them in a selected folder. The UploadFile method is independent of the StdDialogs attribute status and, of course, it is not available when the application is used in desktop mode.
How to change the folder
If you have the need to change the destination folder, you may use the event: ‘onUploadEnd’
Find an example here (zip file).
Nowadays, the Web imposes many necessary security measures which end up limiting the use of web-enabled applications. Thinfinity® VirtualUI manages to integrate remote file handling securely, allowing the user to perform typical operations seamlessly.
VirtualUI File Handling series:
– Upload remote files in VirtualUI web-enabled apps
– Download files from VirtualUI web-enabled apps
How do you ensure the files remain in the selected folder after uploading or downloading. The system seems to clear the temporary folders when the browser session ends?
UploadFile does not work in C++. Compiler complains “no member named UploadFile” in VirtualUI.
I am a trial user only.
Can I change the destination folder of the files to upload from the server administrator?
Indeed, you can use the event ‘onUploadEnd’ to control this. Here is a small demo you can follow:
I’ll add this to the article.
I agree wholeheartedly with Walter. Would you please update the post or post another reply with the answer to Zagreus’ question? (How to know when upload is finished.)
Could You please make this kind of info available to the public too instead of only to the one user who asked?
I think it’s important for everyone using VirtualUI.
It’s very inconvenient to have to ask for an email to get this info.
If You’re in the middle of something and have a time delay of some hours or in my case a day (because of my timezone UTC+2) until I get a response, that’s a big problem.
It would be even better to find something like that in the documentation.
Hi! Thanks for your inquiry! We’ve sent you an email with the answer.
Anytime you have a quick question like this, feel free to open a live chat or email us for a quick response. 🙂
After the upload file directory has been set with m_VirtualUI>>UploadFile(QRY_CurrentUser_Get.Email)
How do you retrieve directory location?
How do I know uploading process has finished?
You can be notified by defining the event VirtualUI.OnDownloadEnd so your custom code will be called with the full file name of the downloaded file, so you can safely delete it, for instance.
Can you provide an example of this event handler, specifically, how to get the full file spec (name and path)?