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.

busboy receive uploaded files from FormData not working for me

See original GitHub issue

Hi, 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: 1437594077838node usage

Another problem is the size of one same pic would vary between different tries.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
morfiescommented, Jul 24, 2015

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.

0reactions
mscdexcommented, Jul 24, 2015

No problem. I’m glad you got it working 😃

Read more comments on GitHub >

github_iconTop 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 >

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