Closed Bug 1625129 Opened 5 years ago Closed 5 years ago

Javascript: Argument 1 of File constructor can't be converted to a sequence

Categories

(Core :: DOM: File, defect)

74 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: tgbv.email, Unassigned)

Details

Attachments

(1 file)

Attached file test.html

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0

Steps to reproduce:

  1. 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>

  1. Open the file
  2. Hit F12 -> go to console tab
  3. Select a new file
  4. 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:

  1. Faulty documentation
  2. Javascript bug
  3. I am missing something

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → DOM: File
Product: Firefox → Core

The documentation says: "An Array of ... Blob". You are passing a blob, not an array of blobs. [file.slice(...)] would probably work.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID

(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!

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: