Skip to main content
1-Visitor
April 17, 2018
Question

Send file from service to external server

  • April 17, 2018
  • 1 reply
  • 2905 views

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"

 

1 reply

1-Visitor
April 18, 2018

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

4erty1-VisitorAuthor
1-Visitor
April 18, 2018
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);
1-Visitor
April 19, 2018

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.