Skip to content
This repository has been archived by the owner on Jan 26, 2021. It is now read-only.

Browser support for uploading files #164

Open
jakuub opened this issue Jan 28, 2016 · 0 comments
Open

Browser support for uploading files #164

jakuub opened this issue Jan 28, 2016 · 0 comments

Comments

@jakuub
Copy link

jakuub commented Jan 28, 2016

Hello,

we use discoveryapis_generator to generate the API for our own service. It is great, but we come to one issue - how to simply upload a file through the API.

We finded out one solution which readed file to upload and convert it to Media like this:

Media fileToMedia(File file) {
  StreamController controller = new StreamController();

  Media media = new Media(controller.stream, 2, contentType: file.type);

  FileReader reader = new FileReader();
  reader.onLoad.listen((ProgressEvent ev) {
    List rawList = reader.result;

    Stream data = new Stream.fromIterable(rawList.map((byte) => [byte]));

    controller.addStream(data).then((_) {
      controller.close();
    });
  });

  reader.readAsArrayBuffer(file);

  return media;
}

but it is very slow workaround, which loaded whole file to RAM (i think) and then upload it. This upload take really long and feeezes whole website, and sometimes causing "website does not respond" error.

Is there some better way to upload the file by the generated API, or should we perform the upload without using the API?

Thank you in advance.

Jakuub

@jakuub jakuub changed the title Browser support for uploading attachments Browser support for uploading files Jan 28, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

1 participant