Search code examples
javascriptnode.jsencodingblobjpeg

Get image in http payload


I am trying to return image as response to http POST request. Image should be returned in payload of http response. Response string:

введите сюда описание изображения

When convert this string to Blob and save, result file is not valid. Converting code:

const blob = new Blob([data], { type: headers['content-type'] });

Solution

  • I finnaly find out reason. To download blob you have to specify that response payload is binary. Example for axios:

    axios.post(endpoint, formData, {
            responseType: 'blob'
        })