Upload an image as binary data

120 Views Asked by At

I'm trying to upload an image to Shopware 6, using the POST api/_action/media/[mediaId]/upload?extension=jpg method with the binary data as body:

{"// binary file body": "[binary data]"}

The binary data is delivered to me as base64.

I'm using "image/jpg" as Content-Type

Although it does go through, and doesn't give any errors, the content doesn't seem to be processed on the other end. If I download the media file, it simply contains the content that I sent.

I'm following the instructions from: https://shopware.stoplight.io/docs/admin-api/c042ae0cd330f-media-management

Maybe I can't send it as base64, or maybe I need to set different headers when i do that?

Kind regards,

Jos

1

There are 1 best solutions below

0
On

You should send binary data directly as content.

Right now you are sending JSON:

{"// binary file body": "[binary data]"}

You should send the binary data directly as a content, without the JSON:

[binary_data]