question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Doesn't work with ajax

See original GitHub issue

I tried 3 approaches: sending JSON with axios, sending FormData with axios, sending FormData with XHR. None worked. req.file was undefined, and req.body was empty.

server

import multer from 'multer';
const upload = multer();

app.post('/api/posts/new', upload.single('image'), function(req, res, next){
	console.log(req.file);
	console.log(req.body);
	res.status(200).json(req.body);
})

I’m using KeystoneJS and serverside rendering React if any of that matters

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Libohan12commented, Dec 10, 2019

@ryanaleksander I think the problem is with passing headers (which has Content-Type,…)from client. I have written a working example using Axios client here : https://gist.github.com/HarshithaKP/ebc0e79800e5638fe827c157360378be

Please let me know if it helps you in resolving your issue. @eric-personal @r3wt This method works, because the file I uploaded is a FileList which results in a file of undeined. thank

1reaction
LinusUcommented, Nov 23, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

jquery ajax function not working - Stack Overflow
When I click on the submit button , my ajax request is not working , it looks as if the control is being...
Read more >
AJAX not working without any error message - CodeProject
I am doing an ajax request using PHP and jQuery but it is not working, also there is no error message. How can...
Read more >
Ajax sometimes work and sometimes just don't work
I'm trying to just randomly edit the ajax or something that related to it, and im delete cache and refresh again and it...
Read more >
Click doesn't work after AJAX load - jQuery - AIO Collective
When I load a website everything works fine until I load new items or replace old once. Ajax still works fine but toggle...
Read more >
jquery function not working after ajax call and .load() - Reddit
The problem is that after I delete an item the dropdown gets updated and then if I try to delete another item it's...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found