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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

How to download TwoDThumbnailURL image file into File Repository

mariaSutton
11-Garnet

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!

9 REPLIES 9

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?

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?

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.

Can you provide an example header for an SSO configured environment?

Also, can you share the link with reference documentation explaining best practice for handling this scenario? 

Thank you,

Maria

I haven't, sorry.

But I would assume you're not using SSO with the OData Connector but a fixed account which is configured in the Configuration Tab of the Odata Connector. This is the account data you must put into the header of the ContentLoader call. Whoever configured "intralox-windchill-odata-connector-illustrated-parts" should be able to give you the credentials.

 

My 2 cents:

  1. Check "disableAuthenticatedContentUrl" parameter in Windchill config.
  2. I remember something about Windchill having some whitelist of IP addresses, for which it permits HTTP Basic authentication. Localhost / 127.0.0.1 is there by default, and that's what allows you to run stuff in Windchill Shell locally without authenticating. You might be able to whitelist your ThingWorx server IP and use some service account to download the file without SSO. ContentLoaderFunctions support HTTP Basic auth. I might be wrong and I don't remember the details, but this should ring a bell for a Windchill consultant. Maybe check in the corresponding section of PTC Community.

/ Constantine

Hi @mariaSutton ,

It appears that a response to this post answers your question.  For the benefit of other Community Members who may have the same question, it would be great if you could designate an appropriate reply as the Accepted Solution.

In the event that this response did not answer your question, please post your current status so that we can continue to support.

Thanks for using the PTC Community!

Regards,

Tony
Announcements


Top Tags