files var in form.parse does not have all the files uploaded
wyu19 opened this issue · 12 comments
Hi, I'm experiencing this issue where the file variable does not include some files that were uploaded.
In my event i can see that I have all the files in the directory: (4)
I then call my api with the formdata created from my html object:
the files variable only has two of the files in the array:
But it uploads all 4 of the files to my tmp folder.
this is my performMultiparty function:
function performMultiparty(req, res, savePath, callback)
{
const form = new multiparty.Form({ autoFiles: true, autoFields: true, uploadDir: savePath });
// Errors may be emitted
// Note that if you are listening to 'part' events, the same error may be
// emitted from the `form` and the `part`.
form.on('error', function(err)
{
console.log(`Error parsing form: ${ err.stack}`);
});
// Parts are emitted when parsing the form
form.on('part', function(part)
{
// You *must* act on the part by reading it
// NOTE: if you want to ignore it, just call "part.resume()"
if (!part.filename) console.log(`Receiving multiparty field: ${ part.name}`);
if (part.filename) console.log(`Receiving multipart file: ${ part.filename}`);
part.resume();
part.on('error', function(err)
{
// decide what to do
});
});
// Close emitted after form parsWed
form.on('close', function()
{
console.log('Upload closed!');
});
// Parse request
// form.parse(req, callback);
form.parse(req, callback);
}
I am not understanding why it is able to upload all the files i selected but doesn't return all the files uploaded in the files variable. I need this so i can rename and move the files. Thanks in advance.
Hello, and sorry you are having this issue. Unfortunately a simple html form and the module I wasn't able to reproduce the issue. Can you please put together all the needed code and steps in order for me to reproduce the issue so I can debug it? Thank you.
Hi I'm not able to piece together all the code needed. Could you show me the example you did?
The example at the top of the readme was all I used: https://github.com/pillarjs/multiparty#usage
Could you show me the flow of how form.parse() works and I can try to debug it on my own?
Hi, I'm not sure what you are looking for in "show me the flow of how form.parse() work". The source code is open in this repo, and debuggers would have a step in feature to step around, add additional break points, etc.
The FormData object is not part of this module. You can read about the methods it has to use to introspect it here: https://developer.mozilla.org/en-US/docs/Web/API/FormData
I've done some debugging and got confused on some parts of the code. The problem seems to be that line 126 and line 127 only executes after the callback is returned. line 103 waitend and req.readable is false so it goes to done() function and returns calls the callback function in line 131 with an empty files object. Why does it not execute line 126 and 127 until after callback?
Hm, strange, it should only do that if there were no files in the request. Are you seeing that only when you are using your upload code at issue or does it also happen when debugging with the example in the readme?
Also I am using 6.14.13 should i be using 4.2.2?
Hi, Im not sure what happened but i was having issues 6.14.13. Then i did npm install again and it downloaded the same version on my code base and everything is working now.