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: Add mimeType to the File instance uploadFile() #5358

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/JSHandle.js
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ class ElementHandle extends JSHandle {
const dt = new DataTransfer();
for (const item of files) {
const response = await fetch(`data:${item.mimeType};base64,${item.content}`);
const file = new File([await response.blob()], item.name);
const file = new File([await response.blob()], item.name, {type: item.mimeType});
dt.items.add(file);
}
element.files = dt.files;
Expand Down
1 change: 1 addition & 0 deletions test/input.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports.addTests = function({testRunner, expect, puppeteer}) {
const input = await page.$('input');
await input.uploadFile(filePath);
expect(await page.evaluate(e => e.files[0].name, input)).toBe('file-to-upload.txt');
expect(await page.evaluate(e => e.files[0].type, input)).toBe('text/plain');
expect(await page.evaluate(e => {
const reader = new FileReader();
const promise = new Promise(fulfill => reader.onload = fulfill);
Expand Down