Uploading image does not seem to grab file.
See original GitHub issueI’m working on getting image uploads to work with react and multer. However multer doesn’t seem to get a req.file
key, only finds req.body.photo
key and holds the value '[object File]'
when I console it out. Multer goes ahead and create the folders specified in destination
but does not store the image there (I’m guessing because it doesn’t have req.file
). If you know what the problem is please reply, and in case you interested in SoF points heres a link:
http://stackoverflow.com/questions/37473634/uploading-images-with-fetch-to-express-using-multer
server.js
var storage = multer.diskStorage({
destination: './public/users',
filename: function (req, file, cb) {
switch (file.mimetype) {
case 'image/jpeg':
ext = '.jpeg';
break;
case 'image/png':
ext = '.png';
break;
}
cb(null, file.originalname + ext);
}
});
var upload = multer({storage: storage});
app.use(upload.single('photo'));
app.post('/uploadUserImage', function (req, res) {
console.log(JSON.stringify(req.body.photo)) // form fields
console.log(req.photo) // form files
console.log(req.file) // form files
res.send(req.body.photo);
});
client.js
function uploadImage (image) {
var formData = new FormData();
formData.append('photo', image);
fetch('http://localhost:8080/uploadUserImage/', {
method:'POST',
body: formData
});
}
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
How to Quickly Fix Image Upload Issues in WordPress
Another sign of this issue is that your images may not appear in the media library. You can then change the file permissions...
Read more >7 Reasons Why Images Are Not Loading on Your Website
1. Incorrect File Paths ... When you add images to a site's HTML or CSS file, you must create a path to the...
Read more >How to Fix Image Upload Issue in WordPress (Step by Step)
First, connect to your website via FTP and then go to /wp-content/ folder. Inside, you'll find the uploads folder, which is where WordPress ......
Read more >Your image upload has failed. What do you do? - Digett
Right click > Properties (for Windows) or Right click > Get Info (for Mac) on your image to see your file size in...
Read more >WordPress Can't Upload Images? Here's How to Fix It
The "WordPress can't upload images" error is common, but with the right techniques, it is possible to fix an image upload issue.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems like this was a client problem that can be solved by the code linked, happy to reopen if we should change something in Multer
Finally, i have got something going with this issue. Processing filelist field like this will send the required payload to server by browser, it was an issue with front end and not multer.