cancel
Showing results for 
Search instead for 
Did you mean: 

Magento 2 Rest API Image upload with c# 'Decode Error'

Magento 2 Rest API Image upload with c# 'Decode Error'

Hi

 

I am using Magento 2.2.6, i want to upload images for Product using rest API with c#

I am converting image using below c# code 

      

   System.IO.Stream fs = File.OpenRead(ImgPath);
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);    Byte[] bytes = br.ReadBytes((Int32)fs.Length);    string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);

API to uploa dImage  : /V1/products/{SKU}/media

below is Request Body 

{
    "entry": {
        "media_type": "image",
        "label": "Image",
        "position": 1,
        "disabled": false,
        "types": [
            "image",
            "small_image",
            "thumbnail"
        ],
        "content": {
            "base64EncodedData": "   base64string   ",
            "type": "image/jpg",
            "name": "img_2.jpg"
        }
    }
}

i am getting Error message : "Decode Error"

Please suggest me

 

1 REPLY 1

Re: Magento 2 Rest API Image upload with c# 'Decode Error'

try with: "type": "image/jpeg"