Skip to main content
12-Amethyst
October 14, 2024
Solved

How to download TwoDThumbnailURL image file into File Repository

  • October 14, 2024
  • 4 replies
  • 2598 views

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!

Best answer by mariaSutton

The solution provided by the PTC Cloud team for this issue was to use MediaEntities["your-integration-odata-connector-with-sso-here].StreamFileRepository

The relativeURL parameter should be modified to start at "/Windchill..."
This function will download the image using your SSO configuration and add the downloaded file to your choice of Thingworx Repo.

 

Thank you everyone for you help!

4 replies

Rocko
19-Tanzanite
October 15, 2024
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});
12-Amethyst
October 15, 2024

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
19-Tanzanite
October 15, 2024

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.

18-Opal
October 23, 2024

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

16-Pearl
November 20, 2024

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,

mariaSutton12-AmethystAuthorAnswer
12-Amethyst
December 2, 2024

The solution provided by the PTC Cloud team for this issue was to use MediaEntities["your-integration-odata-connector-with-sso-here].StreamFileRepository

The relativeURL parameter should be modified to start at "/Windchill..."
This function will download the image using your SSO configuration and add the downloaded file to your choice of Thingworx Repo.

 

Thank you everyone for you help!