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

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

How to download TwoDThumbnailURL image file into File Repository

mariaSutton
10-Marble

How to download TwoDThumbnailURL image file into File Repository

Hi,

I am working on a Thingworx extension that creates an excel file by passing an infotable parameter. The infotable contains strings and TwoDThumbnailURL.URL obtained from `Things["intralox-windchill-odata-connector-illustrated-parts"].GetPartRepresentations`.
So far the TWX extension successfully creates the excel file with string parameters, the challenge is rendering TwoDThumbnailURL images. 

 

I have proven that the downloaded jgp file from TwoDThumbnailURL.URL can be embedded in an excel spreadsheet by doing the following steps: 

  1. Edit TwoDThumbnailURL.URL value by removing the "oauth/" portion
  2. Copy modified TwoDThumbnailURL.URL into the browser
  3. A jpg file is downloaded into local Download directory.
  4. Upload this jpg file to a File Repository.
  5. Now that the image file is available in the File Repository the TWX extension code can obtain the image file and add it in the excel file. 

Is there a programmatic way to do steps 2-4 described above that would download the TwoDThumbnailURL to obtain the jpg file and add it to a File Repository?

TIA!

5 REPLIES 5
Rocko
17-Peridot
(To:mariaSutton)

let image = Resources["ContentLoaderFunctions"].LoadImage({url:"https://www.ptc.com/dist/ptc/images/ptc-favicon-144x144-gray.png"});
Things["SystemRepository"].SaveImage({ path: "/Myimage.png", content: image});

Thanks @Rocko
I tried this out but when the file is downloaded from the repo it was saved to instead of an image the following is rendered:

mariaSutton_0-1728999959150.png

I am using the TwoDThumbnailURL.URL value for the url parameter in LoadImage, this is an example: 

https://<server>/Windchill/oauth/servlet/WindchillAuthGW/wt.fv.master.RedirectDownload/redirectDownload/DPP-1751421.jpg?u8&redirect=true&ContentHolder=wt.viewmarkup.DerivedImage%3A1302633096&HttpOperationItem=wt.content.ApplicationData%3A1302633103&forceDownload=true"

If I remove "oauth" and past in browser the image is downloaded and renders successfully. 

Perhaps I need to further prep/modify the TwoDThumbnailURL.URL before running LoadImage?

Rocko
17-Peridot
(To:mariaSutton)

It looks like the URL you have does a redirect, since you are calling a Servlet on Windchill side. This is then interpreted by the browser, so you don't get the image directly.

You can check the downloaded broken image and open it in a text editor to see what the LoadImage received.

You can also try to download the image from your browser and then use Developer Tools (F12) or Copy Download link from the browser's "Downloads" button to see what is the correct URL.

 

You might have to do a Resources["ContentLoaderFunctions"].GetText first, read the result and get the final URL from there.

The URL is definitely trying to do a redirect, the broken image is returning a Shibboleth Authentication Request message when "oauth" is removed and a "General purpose Windchill error page" when it isn't removed. Same when using GetText function. 
I also tried with Postman with the same results. 

 

Could this be an authentication issue? Any tips to avoid the redirect?

Rocko
17-Peridot
(To:mariaSutton)

Yes, this is about the authentication. When you use the ODataConnector to access Windchill, you configured an authentication with it. But the ContentLoaderFunction does not know about this, it creates its own connection to WT to get the image, but wasn't authenticated. You will have to put the authentication information into the header parameter of the GetText/GetImage call, so Windchill can authenticate the TWX server.

Announcements


Top Tags