busboy receive uploaded files from FormData not working for me
See original GitHub issueHi, someone please come and give me a hand. Big thanks ahead. Here is my server side code:
req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
var name = Date.now()+filename;
var dest = path.join(__dirname + "/../public/uploads/" + name);
console.log(dest);
var writer = fs.createWriteStream(dest);
file.pipe(writer);
req.filename = name;
});
it basically read file streams from request and then pipe to my upload folder with renamed filename.
Client code:
var formData = new FormData();
formData.append("file",$(filename)[0].files[i]);
$.ajax({
url: posturl, //server script to process data
type: 'POST',
data: formData,
cache: false,
contentType: false,
processData: false,
success: function(data){}
});
These codes are just like many a examples do, but files uploaded onto the server are not right for me. The size gets bigger and once I open the uploaded file, most of the images are just broken, with sometimes some images get partly correct like this:
Another problem is the size of one same pic would vary between different tries.
Issue Analytics
- State:
- Created 8 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
busboy on field and on file not firing - node.js - Stack Overflow
It worked yesterday, and now it stopped without any changes made to the code. What is going on? Client async function uploadFile(file) {...
Read more >Terminate busboy from reading more request with unpipe ...
Now busboy won't receive any more pieces of the incoming request. But, as streams work with chunks of 16 kB data, it may...
Read more >How to Implement a File Upload Server with Node.js
In the Node.js server, when receiving the file uploaded by the client, use the busboy module to parse it and save it to...
Read more >File uploads using Node.js - CodeForGeek
I am using this code to upload images into different folders it is working fine but i am not getting post data it...
Read more >Trouble with handling files in Netlify Function - Support
Hi! I'm working on a Netlify Function where we take form data for a job application (including a file upload) and pass the...
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
Hi buddy, I finally figured out what’s wrong with my code. I added req.setEncoding(‘utf-8’); to my req at I don’t know when and why.
After I commented out this line. Everything works as expected, both busboy and connect-busboy
I am terribly sorry for my bad.
No problem. I’m glad you got it working 😃