Hi guys i got a linode server and am trying to make a file upload through an endpoint to my backend server hosted on my linode server, when i upload files less than 1-2 mb it works but above that it doesn’t, i tried testing same upload functionality using heroku it worked, but it doesn’t work on my linode server instead my axios returns a “network error” please is there any config i need to do to allow large file upload am using react axios, node js and multer.
my code
try{
const formData = new FormData();
formData.set('txt', textValue)
formData.set('post_for', PostFor)
fileList.forEach(element => {
formData.append('files', element)
})
setloading(true)
setError();
axios.post(`${ENDPOINT}/feed/`, formData,{
headers:{token:localStorage.token,"Content-Type":"multipart/form-data"},
onUploadProgress: (data) => {
setProgress(Math.round(100 * (data.loaded / data.total)));
},
}).then(res => {
if(res.data){
setloading(false)
setFileList([])
setpreviewImage([])
setpreviewVideo([])
setText('')
setError();
socket.emit('refresh_feed')
message.success('feed uploaded successfully')
setTimeout(()=>{
setProgress()
},6000)
}else if(res.error){
setloading(false)
message.error(res.error)
}
}) .catch((error) => {
const code = error
switch (code) {
case "FILE_MISSING":
setError("Please select a file before uploading");
setloading(false)
break;
case "LIMIT_FILE_SIZE":
setError("File size is too large. Please upload files below 1MB!");
setloading(false)
break;
case "INVALID_TYPE":
setError(
"This file type is not supported. Only .png, .jpg, and .jpeg files are allowed"
);
setloading(false)
break;
default:
setError("Sorry, something went wrong");
setloading(false)
break;
}
});
}catch (error) {}
}
const storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, `./src/uploads`)
},
filename: function (req, file, cb) {
// if(file.mimetype === 'video/mp4' || file.mimetype === 'audio/mpeg'){
// return cb(null, Date.now() + '.mp3')
// }
cb(null, Date.now() + path.extname(file.originalname))
}
})
export const upload = multer({ storage: storage })