question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

uploaded files should be iterable

See original GitHub issue

Current upload implementation sets the target element files to an object that matches the type definition for FileList. JSDOM and browsers implement FileList extending from Array, allowing them to be iterable (for example, one can perform [...element.files]). With the current implementation, after performing the upload, the attribute is not iterable.

sandbox with a demonstration: https://codesandbox.io/s/blazing-sunset-l6izw

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
vadimshvetsovcommented, May 20, 2020

At first I was tried to implement function for emulating FileList but it’s not possible with current FileList implementation in jsdom.

function createFileList(files) {
  const fileList = new FileList(); // Illegal constructor
  for (const [index, file] of files.entries()) {
    fileList[index] = file;
  }
  fileList.item = (index) => fileList[index];
  return fileList;
}

Thats because of this line. So I see no clean option to make files as FileList at now. Here is the issue in jsdom we can keep eye on.

About iteration I’m not sure although its convenient to use. FileList is not marked as iterable in specs. What do you think @kentcdodds about supporting iteration as Chrome and Firefox do but not Edge (there is a proof in comments of this answer)?

2reactions
vadimshvetsovcommented, May 19, 2020

Hi, @rbusquet! Thanks for describing a problem here.

I’d tried to implement from the start upload as a FileList as close as possible because it cannot be created and a readonly unfortunately. The only way to create FileList is with DataTransfer constructor which has no reliable node polyfill as I’ve found.

Your case looks common and I will think about how to make it works with another PR.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSV List Import Best Practices
Iterable allows you to upload CSV files of subscribers and their user profile fields. It's a great way to create new static lists...
Read more >
Not being able to iterate line by line over a uploaded file ...
You problem, based on this.firstfile.split is not a function or its return value is not iterable error, is that you are trying to...
Read more >
How to Send a PDF File in Iterable
1. Log into your Digioh account, click on Files, and click on “Upload File” · 2. Click on the PDF you just uploaded...
Read more >
Getting 'builtin_function_or_method object is not iterable' ...
[Solved]-Getting 'builtin_function_or_method object is not iterable' on file upload-django · Your model Seekers should rather be named Seeker using the singular, ...
Read more >
dcc.Upload... "TypeError: 'float' object is not iterable"
Basically I have two upload buttons that returns stuff back to 2 corresponding ... Traceback (most recent call last): File "/comparison.py", ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found