Magento 2 – How to Upload Image to REST API (POST)

apiimage-uploadmagento2

I'm working with a Magento 2 project that need to upload image using a POST endpoint

How can I send image content to this endpoint?

Or I have to base64 the image at client side and send the base64 content to POST endpoint?

Thank you very much.

Best Answer

If you want to upload product image using rest api. You need to pass below parameters in your request.

Your media upload url - http://127.0.0.1/megento2/index.php/rest/V1/products/{sku}/media.

Method name - Post

Below are the body parameters :

[
  {
    "id": 0,
    "media_type": "test",
    "label": "test",
    "position": 0,
    "disabled": true,
    "types": [
      "thumbnail"
    ],
    "file": "test.png",
    "content": {
      "base64_encoded_data": "Here i have passed base64_encoded data of image",
      "type": "file/png",
      "name": "test.png"
    },
    }
  }
]

Note : Make sure you pass base64_encoded_data of image.

Related Topic