I am trying to upload a file using Axios and send it to a strapi local server. This is how I am sending the data with Axios
const Form = () => {
const [selectedFile, setSelectedFile] = React.useState(null);
const handleSubmit = async (event) => {
event.preventDefault();
const formData = new FormData();
formData.append("selectedFile", selectedFile[0]);
try {
const response = await axios({
method: "post",
url: "http://localhost:1337/document-uploads",
data: formData,
headers: { "Content-Type": "multipart/form-data" },
});
} catch (error) {
console.log(error);
}
};
const handleFileSelect = (event) => {
setSelectedFile(event.target.files[0]);
};
return (
<form onSubmit={handleSubmit}>
<input type="file" onChange={handleFileSelect} />
<input type="submit" value="Upload File" />
</form>
);
};
export default Form;
The message that I am getting is: error 400 and "when using multipart/form-data you need to provide your data in a json 'data' field"