I would like to upload an image to strapi with a html file. When I run the code, I obtain the error: POST http://localhost:1337/upload 500 (Internal Server Error).
As of today, you can upload a file to strapi using axios with the following code. This is the handler of the input event on a file input.
onInput (files) {
const axios = require('axios')
const STRAPI_BASE_URL = 'http://localhost:1337'
const formData = new FormData()
formData.append('files', files)
formData.append('ref', 'restaurant') // optional, you need it if you want to link the image to an entry
formData.append('refId', 12345) // optional, you need it if you want to link the image to an entry
formData.append('field', 'image') // optional, you need it if you want to link the image to an entry
axios.post(`${STRAPI_BASE_URL}/upload`, formData)
}
I assume that you have a collection called restaurant
with a field image
of type file.
More on this here: https://strapi.io/documentation/v3.x/plugins/upload.html#upload-files