Answer the question
In order to leave comments, you need to log in
Why is the image not always updating in React?
I use axios to send an image file to the server
export const uploadPhoto = ({file}) => {
const formData = new FormData();
formData.append('file',file);
const config = {
headers: {
'content-type': 'multipart/form-data'
}
}
return (dispatch) => {
return axios.post(`${apiUrl}/uploadavatar`,formData,config)
.then(response => {
setTimeout(function(){
dispatch({type: 'USER_INFO', info: response.data})
},300)
})
.catch(error => {
console.log(response)
throw(error);
});
};
};
fs.mkdirs(currpath,function(err){
let form = new formidable.IncomingForm();
form.uploadDir = path.join(process.cwd(),currpath);
form.parse(req);
form.on('fileBegin', function (name, file){
console.log('begin')
file.path = path.join(dir,namedir,file.name);
});
form.on('progress', function(bytesReceived, bytesExpected) {
var percent_complete = (bytesReceived / bytesExpected) * 100;
// console.log(percent_complete.toFixed(2));
});
form.on('file', function (name, file){
console.log('Uploaded ' + file.name);
res.send('success');
});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question