Javascript: Argument 1 of File constructor can't be converted to a sequence
Categories
(Core :: DOM: File, defect)
Tracking
()
People
(Reporter: tgbv.email, Unassigned)
Details
Attachments
(1 file)
|
415 bytes,
text/html
|
Details |
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0
Steps to reproduce:
- Save the following code to a HTML file
<html>
<head><title>test</title></head>
<body>
<input type="file" id="file" onchange="__func(this)">
</body>
<script>
function __func(target)
{
let file = target.files[0];
file = new File(
file.slice(0, file.size),
file.name,
{type: 'text/csv'}
);
console.log(file);
}
</script>
</html>
- Open the file
- Hit F12 -> go to console tab
- Select a new file
- Watch console.
Actual results:
I got the following error:
TypeError: "Argument 1 of File constructor can't be converted to a sequence."
Expected results:
I expected in Console to receive the information about new file blob.
In documentation is stated that a File constructor can accept an object of type Blob (https://developer.mozilla.org/en-US/docs/Web/API/File/File)
In documentation is also stated that Blob.slice() returns a new Blob (https://developer.mozilla.org/en-US/docs/Web/API/Blob/slice)
Therefore I should be able to pass value returned by Blob.slice() as first parameter to File constructor.
Possible reasons for such behaviour:
- Faulty documentation
- Javascript bug
- I am missing something
Comment 1•5 years ago
|
||
Bugbug thinks this bug should belong to this component, but please revert this change in case of error.
Comment 2•5 years ago
|
||
The documentation says: "An Array of ... Blob". You are passing a blob, not an array of blobs. [file.slice(...)] would probably work.
| Reporter | ||
Comment 3•5 years ago
|
||
(In reply to Tom Schuster [:evilpie] from comment #2)
The documentation says: "An Array of ... Blob". You are passing a blob, not an array of blobs.
[file.slice(...)]would probably work.
Did the trick. Thank you!
Description
•