node-formidable / formidable

The most used, flexible, fast and streaming parser for multipart form data. Supports uploading to serverless environments, AWS S3, Azure, GCP or the filesystem. Used in production.
MIT License
7.06k stars 682 forks source link

Failed to retrieve/set file extension when upload file as blob #366

Closed creeperyang closed 4 years ago

creeperyang commented 8 years ago

What I upload:

------WebKitFormBoundaryi8ZhzSYa1jK76hJC
Content-Disposition: form-data; name="tags"

56a1f2c06dfc44c4570a46cb,56a1f2c06dfc44c4570a46cc
------WebKitFormBoundaryi8ZhzSYa1jK76hJC
Content-Disposition: form-data; name="headImg"; filename="blob"
Content-Type: image/jpeg

------WebKitFormBoundaryi8ZhzSYa1jK76hJC--

The problem is that when handle File and ouput a Blob instance, and then upload this blob, the filename's extension will lost (client only sent filename="blob").

So the IncomingForm.prototype._fileName will return "blob" as the file.name.

And IncomingForm.prototype._uploadPath will generate path without extension (although this.keepExtensions is true) and all saved files lost their extension.

I'm not sure it's a better way to retrieve and add extension from Content-Type: image/jpeg, or just leave it with no extension.

art-in commented 8 years ago

I'm using chrome (v52) and does not see such effect.

case:

let file = input.files[0];

let data = new FormData();
data.append('photo', photo);

fetch(`url`, {
    method: 'POST',
    body: data
});

request:

------WebKitFormBoundary76WmHIDQOjBC1dKX
Content-Disposition: form-data; name="photo"; filename="___.jpg"
Content-Type: image/jpeg

File name is in place.

creeperyang commented 8 years ago

Um, It's chrome v46/v48 (v40+, not v50+) when I report this issue.

Maybe things changed when chrome updated.

tunnckoCore commented 7 years ago

@creeperyang can you try it and report back when you can?

zhancheng commented 7 years ago

cause this issue, because the third argument does not set formdata.append('blobdata', blob, filename);

GrosSacASac commented 4 years ago

This looks like to be a client side issue