Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example for posting product images #6

Open
bnoffer opened this issue May 11, 2017 · 3 comments
Open

Example for posting product images #6

bnoffer opened this issue May 11, 2017 · 3 comments

Comments

@bnoffer
Copy link

bnoffer commented May 11, 2017

Hi,

I tried to upload new product images via the API, but was unable to figure out the way how it is done properly. Is there a example available or has someone implemented this successfully?

Thanks in advance!

@alirnz
Copy link

alirnz commented May 18, 2017

@bnoffer you found solution?, i am also stuck at that part.. trying to do some thing like this
{
"product": {
"name": "test product api hello through short new new3",
"full_description": "hello this is test1111",
"short_description": "this is hello",
"image": [{
"src": "http://cdn.lib-tech.com/wp-content/uploads/2016/07/2016-2017-Lib-Tech-Skate-Banana-Yellow-Snowboard-800x800.png",
"attachment": ""
}]
}
}

but no luck

@bnoffer
Copy link
Author

bnoffer commented May 22, 2017

sadly not.

I tried different variations incl. attachments etc., some went through without error, but no image showed up, some came back with an error.

@spielinger
Copy link

spielinger commented Aug 5, 2017

Hi!

After some debugging I found out, how to upload images via the API. Here are some code snippets:

ImageDto idto = new ImageDto();
byte[] imgByteArray = ImageToByteArray(iPicture);
String base64String = Convert.ToBase64String(imgByteArray, Base64FormattingOptions.None);
idto.Attachment = base64String;
idto.MimeType = "image/x-png";
categoryJson.category.Image = idto;
...
string cCategoryJson = JsonConvert.SerializeObject(categoryJson, Formatting.None, new
JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
...
static public byte[] ImageToByteArray(System.Drawing.Image imageIn)
{
using (var ms = new System.IO.MemoryStream())
{
imageIn.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
return ms.ToArray();
}
}

It is important to assign only "Attachment" and "MimeType" and to leave "Src" and "Binary" empty. The byte array for "Attachment" has to be a base 64 encoded string.

Hope this helps.

iwhp pushed a commit to iwhp/nopCommerce-api-sampleapplication that referenced this issue Aug 22, 2018
… i.e api/orders/{orderId}/order_items is now just api/orders/{orderId}/items
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants