pillarjs/multiparty

files var in form.parse does not have all the files uploaded

wyu19 opened this issue · 12 comments

wyu19 commented

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)
image

I then call my api with the formdata created from my html object:
image

image

the files variable only has two of the files in the array:
image

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.

wyu19 commented

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

wyu19 commented

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.

wyu19 commented

Also is there a way for me to verify my formdata is correct? When i create it based on my form i see that its an object:
image

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

wyu19 commented

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?
image

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?

wyu19 commented

This seems to only happen inside my codebase. I have two seperate examples in the readme. One in a seperate folder from my code and i see the file filed being populated:
image

but in the example that i have inside my code base it does not have the object:
image

wyu19 commented

Also I am using 6.14.13 should i be using 4.2.2?

wyu19 commented

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.