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

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

ContentLoader post methods

arunkumar1
12-Amethyst

ContentLoader post methods

Hi,

I have an external URL (POST method) which consumes "application/json" and produces "application/pdf".

Which content loader post method should I use?

PostJSON takes JSON content however the return type shows as JSON

var myHeader = {

    Accept: "application/pdf"

};

var contentJSON = {"key":"value"};

var params = {

  headers: myHeader,

  url: "my external url",

  content: contentJSON,

};

// result: JSON

var result = Resources["ContentLoaderFunctions"].PostJSON(params);

But, I get the following error when invoking the service:  Unable To Convert From org.json.JSONObject to BLOB

Regards

Arunkumar D

2 REPLIES 2

If you're doing that so that the pdf is directly loaded to the client's browser: it doesn't work (I already tried. But if you manage to do so, I'd be interested to know and you may become my new god).

To answer directly to your question, PostJson is waiting for JSON objects (This is the Thingworx mechanism) and you send a file (blob).

It just cannot andle that type.

Hi,

I don't necessarily have to show it in the client browser.

I want my service to fetch the PDF file from the external URL and store it using FileRepository thing.

Fetching PDF using the above said PostJSON is where I'm facing issues.

If I use PostBinary, I'm getting following error:

     Wrapped java.lang.Exception: Unable To Convert From org.json.JSONArray to BLOB Cause: Unable To Convert From org.json.JSONArray to BLOB

If I had to use LoadBinary, how to send the JSON content to the 3rd party URL? Because the LoadBinary params doesn't contain "content" attribute.

Please let me know.

Regards

Arunkumar D

Announcements


Top Tags