Created
June 27, 2022 14:01
-
-
Save joao-pedrozo/545076b4867311dd99a7b1b4b3aba353 to your computer and use it in GitHub Desktop.
Upload image to strapi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
const formData = new FormData(); | |
const { data: stream } = await axios.get( | |
"https://images.unsplash.com/photo-1611095785020-1ba3dd228ea7?ixid=MXwxMjA3fDF8MHxlZGl0b3JpYWwtZmVlZHwxfHx8ZW58MHx8fA%3D%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=900&q=60", | |
{ responseType: "stream" } | |
); | |
formData.append("files", stream); | |
formData.append("ref", "api::article.article"); // Collection name | |
formData.append("refId", 10); // Item ID | |
formData.append("field", "thumbnail"); // Field Name | |
await axios.post(`${API_URL}/upload`, formData, { | |
headers: { | |
"Content-Type": "multipart/form-data", | |
Authorization: `Bearer ${API_TOKEN}`, | |
}, | |
}); | |
} catch (err) { | |
console.log(err.response.data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment