We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hi I tried this code below with values for both caption and filename:
` let formData = new FormData();
formData.append('caption', caption);
formData.append('file', { name: filename });
console.log('upload File formData: ', formData);
axios.post('http://localhost:9890/', formData) .then((response) => { response.data.success ? alert('File successfully uploaded') : alert('File already exists'); this.fetchRecent(); }) .catch(err => alert('Error: ' + err)); `
When I uploaded an image file, on the server side, the logging showed the req.body is empty and req.file is undefined:
Upload single file req.body: {} Upload single file req.file: undefined
The server side code:
` imageRouter.route('/')
.post(upload.single('file'), (req, res, next) => { console.log(req.body); // check for existing images Image.findOne({ caption: req.body.caption }) .then((image) => { console.log(image); if (image) { return res.status(200).json({ success: false, message: 'Image already exists', }); }
` ... Do you have an idea what I did wrong? Thanks
The text was updated successfully, but these errors were encountered:
because in
you just gave name try to even give value
append(name, value)
Sorry, something went wrong.
No branches or pull requests
Hi I tried this code below with values for both caption and filename:
`
let formData = new FormData();
formData.append('caption', caption);
formData.append('file', {
name: filename
});
console.log('upload File formData: ', formData);
axios.post('http://localhost:9890/', formData)
.then((response) => {
response.data.success ? alert('File successfully uploaded') : alert('File already exists');
this.fetchRecent();
})
.catch(err => alert('Error: ' + err));
`
When I uploaded an image file, on the server side, the logging showed the req.body is empty and req.file is undefined:
Upload single file req.body: {}
Upload single file req.file: undefined
The server side code:
`
imageRouter.route('/')
`
...
Do you have an idea what I did wrong?
Thanks
The text was updated successfully, but these errors were encountered: