Community Tip - New to the community? Learn how to post a question and get help from PTC and industry experts! X
Is it possible to download a file inside Thingworx service?
I wrote a service to archive a zip file,
I want to after the file is archived it also downloads inside the service called
Note that this service will return Nothing.
Solved! Go to Solution.
That is much more complex.
When the browser receives in a page a download link, the actual download process is no longer happening in the context of the page. The browser handles the file download process and it does not inform the page that the download finished. That is just the way the current HTML5 implementation and browser architecture works.
If you want to be 100% deterministic, you need to create a new widget which downloads the file internally and then allows you to either open or save. Downloading the file in the document allows you to understand then the download finished and then you can trigger a "FileDownloaded" widget Event .
I've googled a link that shows how you can do this: https://stackoverflow.com/questions/23451726/saving-binary-data-as-file-using-javascript-from-a-browser/23451803#23451803
It should be relatively easy to do, if you have previous widget building experience
I have not understood your requirement completely. But probably this article will help.
Thanks @rjanardan
For instance:
I have a Thingworx Service when user click a button to call
This service will do
1. Create an Archive zip file
2. Download the zip file from #1
How can I implement #2?
Thanks!
Hi @vxba ,
For number 2, you can use a additional Link widget and a single service.
Step 1. You will know the name of the archive file and the repository. You must build based on that service input - ideally as its output, a Download URL for your file. That has a simple format - use the service GetFileListingWithLinks from any FileRepository to see an example of how the Download Link is formed
Step 2. Assign that service output as the LinkURL property of the Link widget.
Step 3. Based on the service invoke completed, trigger the "Navigate" service of the same Link widget.
You can maybe set the Link to invisible and just have the download window popup?
Note: there might be a race condition between step 2 and 3 - keep an eye for that.
Thanks @VladimirRosu
I have tried that solution.
but I have a new issue that I need to delete that file after it's downloaded so when we use Link widget to trigger the link I cannot control when will the file is downloaded.
Do you have any solutions to know when the file is download completed?
That is much more complex.
When the browser receives in a page a download link, the actual download process is no longer happening in the context of the page. The browser handles the file download process and it does not inform the page that the download finished. That is just the way the current HTML5 implementation and browser architecture works.
If you want to be 100% deterministic, you need to create a new widget which downloads the file internally and then allows you to either open or save. Downloading the file in the document allows you to understand then the download finished and then you can trigger a "FileDownloaded" widget Event .
I've googled a link that shows how you can do this: https://stackoverflow.com/questions/23451726/saving-binary-data-as-file-using-javascript-from-a-browser/23451803#23451803
It should be relatively easy to do, if you have previous widget building experience