POST <input> file as binary/octet-stream Content-Type using Axios

Viewed 657

My plan is to upload a file received from an input tag, to an S3 bucket. I need to manage a way to pass that file of type [Object file] into a supported type for the header of my API "Content-Type: "binary/octet-stream". But I've tried using Buffer.from(), .toString("base64") but none of these made any changes.

This is the API POST request:

export async function sendToS3(uploadURL, file) {
  let request = {
    method: "PUT",
    url: uploadURL,
    headers: {
      "Content-Type": "binary/octet-stream",
    },
    data: file
  };

  const response = await axios(request);
  return response.data;
};

And this is how the received file looks, which I need to send to S3:

File {
  name: "filename.jpg",
  lastModified: "1652758134934",
  size: "64058",
  type: "image/jpeg",
  webkitRelativePath: "folderName/filename.jpg"
}
0 Answers
Related