cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Snippet to download a file via a service?

SOLVED
Highlighted
Aquamarine

Snippet to download a file via a service?

Is there a code snippet to download a file from a repository? I'm looking to download a file from within a service.

I want to avoid having to use a widget (e.g. link or data export), and wondered if there was any way to kick off a download from within a script. I realise I can use the GetFileListingsWithLinks to get the url, but how can I then activate that url from within a service.

 

What I actually want to happen is: on the click of a button I want to run a service that creates a file, writes some data (based on some user defined parameters), saves it, then automatically begin the download. Ideally after the download I would like to delete the file.

 

TIA

K

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted

Re: Snippet to download a file via a service?

You could use content loader functions to utilize REST calls for export:

https://www.ptc.com/en/support/article?n=CS224211

(using content loader functions:  https://www.ptc.com/en/support/article?n=CS237875 )

 

You'd use the value/URL obtained previously.

View solution in original post

4 REPLIES 4
Highlighted

Re: Snippet to download a file via a service?

Hi, 

 

With what we have out of the box, you can either create a service on your FileRepository thingA or on another thing and reference thingA (when creating a service, go to Me/Entities and select the entity). Then you could do something like this:

 

// result: INFOTABLE dataShape: "FileSystemFileWithLinks"
var result = Things["TestingRepo"].GetFileListingWithLinks({
path: undefined /* STRING */,
nameMask: undefined /* STRING */
});

 

and place the result into a grid to select the URL, or write another service to fetch the url from the infotable result of the first service.

 

Highlighted

Re: Snippet to download a file via a service?

Hi,

thanks for the reply. I'm trying to find a solution which doesn't involve using a grid if possible. I understand your suggestion about writing a service to return the link, but the bit I am struggling with is how to initiate the download from within the service once I have the download link.

 

Ideally what I want to do is have a single button which will generate a file and then automatically begin to download that file to my PC.

Highlighted

Re: Snippet to download a file via a service?

You could use content loader functions to utilize REST calls for export:

https://www.ptc.com/en/support/article?n=CS224211

(using content loader functions:  https://www.ptc.com/en/support/article?n=CS237875 )

 

You'd use the value/URL obtained previously.

View solution in original post

Highlighted

Re: Snippet to download a file via a service?

That is very helpful! thank you 

run 3

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________