The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.
 
 
Thread Tools Display Modes
  #1  
Old 06-15-2015, 08:46 AM
OhSami's Avatar
OhSami is offline
 
Join Date: May 2015
Posts: 1
Default

Automatically Uploading Product Images - results in a 422


I am using code like:
Code:
function UploadImage(id, url) {
	console.log([id, url]);
	request(url).pipe(fs.createWriteStream(id + '.png'))
	unirest.post('https://app.ecwid.com/api/v3/' + apikeys[0] + '/products/' + id + '/image?token=' + apikeys[1])
	.headers({'Content-Type': 'application/json'})
	.attach('file', id + '.png')
	.end(function (response) {
		console.log(response.statusCode);
		console.log(response.body);
	});
}
And it result in a 422, what can I do to find out what is wrong with the image, as 422 suggests that "The uploaded file is not an image" when it definitely is, probably just not compatible; anything within NodeJS that I can leverage to convert/check whats going on?

Any help would be great.
  #2  
Old 06-17-2015, 04:17 PM
Rick G's Avatar
Rick G Rick G is offline
Ecwid Team
 
Join Date: Jun 2014
Posts: 1,271
Default

Quote:
Originally Posted by OhSami View Post
I am using code like:
Code:
function UploadImage(id, url) {
	console.log([id, url]);
	request(url).pipe(fs.createWriteStream(id + '.png'))
	unirest.post('https://app.ecwid.com/api/v3/' + apikeys[0] + '/products/' + id + '/image?token=' + apikeys[1])
	.headers({'Content-Type': 'application/json'})
	.attach('file', id + '.png')
	.end(function (response) {
		console.log(response.statusCode);
		console.log(response.body);
	});
}
And it result in a 422, what can I do to find out what is wrong with the image, as 422 suggests that "The uploaded file is not an image" when it definitely is, probably just not compatible; anything within NodeJS that I can leverage to convert/check whats going on?

Any help would be great.
Hi,

Thank you for contacting us.

As I can see, you are using Ecwid API to upload images for your products.

According to our documentation: http://developers.ecwid.com/api-docu...-product-image in order to do that, you will need to make a request to Ecwid API with the following parameters:

POST https://app.ecwid.com/api/v3/{storeId}/products/{productId}/image?token={token}

Also, you will need to make sure that the file itself is passed as a binary data, because the 422 error is most likely displayed because the file is not passed as binary data.

As I can see, you were able to successfully upload an image using Ecwid API for the product: 51487039, 51510245, 51510244.

Possibly these links will be helpful to find out how to upload binary data in Node.js:
http://stackoverflow.com/questions/2...y-data-in-post
http://blog.modulus.io/node.js-tutor...request-module
http://www.componentix.com/blog/13/f...ejs-once-again

Thank you.
__________________
Ecwid API and App Market Team
Ecwid Developer Website

Last edited by Vitaliy G; 01-04-2016 at 12:27 PM.
 
The information in this thread might be outdated
If the solution did not help, please, check our Help Portal or contact Ecwid Team.

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 01:21 AM.
Powered by vBulletin® Version 3.8.11. Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.