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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

Send file from service to external server

4erty
6-Contributor

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
chaitanya
7-Bedrock
(To:4erty)

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

4erty
6-Contributor
(To:chaitanya)

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);
chaitanya
7-Bedrock
(To:4erty)

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.

4erty
6-Contributor
(To:chaitanya)

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".

Top Tags