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

Send file from service to external server

Regular Member

Send file from service to external server

Can I send image file from FileRepository using Thinworx service to the external php server? 

Try using Resources["ContentLoaderFunctions"].PostImage(params), but it throw exception

"Unable To Convert From [B to JSON"

 

4 REPLIES 4

Re: Send file from service to external server

could you please try converting the imageFile to base64 and then try sending it in params.

Highlighted

Re: Send file from service to external server

I add base64encodeString from snippets, but have same exception message. That's my code, may be you can find my error. I am using Thingworx 6.5.2
var Content = Things["NearmissImages"].LoadImage({ path: '/bag.jpg' })

var encodedValue = base64EncodeString(Content);

var params = {
    headers: {"ContentType" : "multipart/form-data"},
	ignoreSSLErrors: true,
	mimeType: 'image/jpeg',
	url: 'http://143.39.248.12/esystem/php/test.php',
	content: encodedValue,
	timeout: 10000
};

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

Re: Send file from service to external server

Could you try loading the image first then convert it to base64 and do a simple rest request to your page with base64 string as body.

Re: Send file from service to external server

Which snippet do I need to use to convert an image to Base64? 

I try to use base64DecodeBytes and base64DecodeString, but they throw exception "Invalid length".

Announcements

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