cancel
Showing results for 
Search instead for 
Did you mean: 

Upload non image files via REST API

Upload non image files via REST API

I am working with magento's REST API. I am trying to add a product to cart and uploading a non image file as product's custom attribute (after converting the file content to base64) but its not working , The API send an error "The image content must be valid base64 encoded data." If I upload an image it works fine, but my end goal is to upload different formats like pdf, txt etc.  Does the API support uploading of non image file formats via API ?

 

Request Body

{
  "cartItem": {
    "sku": "test-product",
    "qty": 1,
    "quote_id": "199",
    "product_option": {
      "extension_attributes": {
      	"customOptions": [
        {
          "optionId": "1925",
          "optionValue": "file",
          "extensionAttributes": {
            "fileInfo": {
              "base64EncodedData": "SGVsbG8=",
              "type": "Text",
              "name": "text.txt"
            }
          }
        }
      ]
      }
    }
  }
}
1 REPLY 1

Re: Upload non image files via REST API

No by default - there is no non image file formats Upload functionalities via API.

 

Still as you are passing base64encode Data as parameter.

 

Do one thing in type - you still give type": "file/jpg" and keep base64encoded Data which you are passing as it is.

 

Then check if it works then good - other wise you need to create your own custom API to achieved this kind of functionality.

if issue solved,Click Kudos & Accept as Solution