Closed laurisvan closed 2 years ago
You should be able to use a native FileList
instance, or, File
instances in arrays or as object properties, anywhere really.
Found the original problem - it was in my link handler (I checked from the values whether they were Files or Blobs, but did not handle arrays of Files or Blobs). After the change, it works just fine with an array of Files (File[]).
However, I cannot still understand the FileList related test in this project but cannot confirm it would not work. I'll close this issue, but I'd still recommend checking why and how the FileList implementation would work as it does not utilise a public api of FileList. I would assume the docs in MDN are correct, and they declare FileList class only has a method called item
and a property called length
(https://developer.mozilla.org/en-US/docs/Web/API/FileList). The .files() is a method of DataTransfer.
I am currently working with a GraphQL mutation passing multiple files as an input in form of [Upload!], but struggling to get it work. No matter what I do, the output from GraphQL does not seem to send the binaries, but an array of JSON.stringified Files.
Initially the problem was that I was passing an array of File instances, but after reading README of jaydenseric/apollo-upload-client, it seems that I should pass a FileList. Due to using a few 3rd party dependencies, I cannot get a native FileList directly from my code (only an array of Files), so I needed to adapt them to a FileList using a DataTransfer as follows:
According to DataTransfer API (https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer), this should return a FileList, but that one still gets stringified. I checked the related test in this project, and it seems that it expects some object with
files
method which is not part of FileList.What is the actual API that should be returned? It looks almost as if it were DataTransfer that should be passed - not FileList?