material-ui-dropzone
material-ui-dropzone copied to clipboard
I can't able to upload files using axios.
I'm using axios and dialog dropzone, everything works fine but I cant able to upload files to the server.
You can crearte formData and for files you would be use .map and send information for example for many files
const bodyFormData = new FormData(); files.map(file =>bodyFormData.append("file", file))
and the axios I create a function
const response = await fethWithTokenMultiData('projects/create',bodyFormData)
and function use 'multipart/form-data'
export const fethWithTokenMultiData = async(endpoint,data=null,fileType='multipart/form-data') =>{
const url = 'example url';
const token = localStorage.getItem('token') || '';
const config = {
headers: {
'Authorization':token,
'Content-Type': fileType
}
}
try {
const response = await axios.post(url,data,config)
return response
} catch (error) {
console.log(error);
}
}