Send image with fetch API

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the javascript category.

Last Updated: 2024-11-23

// Create a form data entity
const formData = new global.FormData();
formData.append(
  "image", {name: "image.jpeg", type: "image/jpg", uri: imageUri}
)

return fetch(url, {
  method: "POST",
  // Needs this header
  headers: {
    "Content-Type": "multipart/form-data",
  },
  body: formData
}).then()