Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(): default filename for blob #345

Merged
merged 3 commits into from
Jul 7, 2020
Merged

fix(): default filename for blob #345

merged 3 commits into from
Jul 7, 2020

Conversation

ikosta
Copy link
Contributor

@ikosta ikosta commented Jun 25, 2020

Background

Mozilla FormData.append filename (optional):
The filename reported to the server (a USVString), when a Blob or File is passed as the second parameter. The default filename for Blob objects is "blob". The default filename for File objects is the file's filename.

How the browser works

Basically the filename blob is set by formData.append if blob with no filename is passed.
(I tested this on Safari, Chrome, Firefox, iOS and Android)

// no filename passed
formData = new FormData();

formData.append('json', new Blob(['{"bla":1}'], {type: 'application/json'}));

console.log(formData.entries().next().value[1].name); // will print 'blob'

// empty filename passed
formData = new FormData();

formData.append('json', new Blob(['{"bla":1}'], {type: 'application/json'}), '');

console.log(formData.entries().next().value[1].name); // will print ''

What the plugin does wrong

In the plugin www\helpers.js:456:

result.fileNames.push(entry.value[1].name || 'blob');

And here is the empty filename always overwritten with blob.

How to fix

In the plugin www\helpers.js:456:

result.fileNames.push(entry.value[1].name !== undefined ? entry.value[1].name : 'blob');

Now the filename is only set to blob if it is not defined at all.

Tests

I also added two test to cover all scenarios and fixed the FileMock for that.

@ikosta
Copy link
Contributor Author

ikosta commented Jul 4, 2020

@silkimen what do you think about that fix?

@silkimen
Copy link
Owner

silkimen commented Jul 5, 2020

Hi @ikosta, basically this look good to me, but one of the e2e specs is failing. Maybe you can elaborate what's going wrong here?

CleanShot 2020-07-05 at 14 54 13@2x

@ikosta
Copy link
Contributor Author

ikosta commented Jul 6, 2020

Hi @silkimen, I just pushed a fix in the ponyfills.

@silkimen
Copy link
Owner

silkimen commented Jul 7, 2020

CleanShot 2020-07-07 at 10 59 11@2x

www/ponyfills.js Outdated Show resolved Hide resolved
Co-authored-by: Sefa Ilkimen <[email protected]>
@silkimen silkimen merged commit f43b2f9 into silkimen:master Jul 7, 2020
@silkimen
Copy link
Owner

silkimen commented Jul 7, 2020

Thank you @ikosta 🎉

ath0mas pushed a commit to ns0m/cordova-plugin-advanced-http that referenced this pull request Feb 6, 2024
fix(): default filename for blob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants