How to create a File object from a web URL with .fromUri(Uri.parse(link)) with Dart?

61 Views Asked by At

I have a variable storing a list of images uploaded to Firebase, and I am trying to create a File object for all of them to add them to an ArchiveFile object to create a zip file of those images. Here is my code below:

  for (var i = 0; i < trainingData.length; i++) {
    print(trainingData[i]);
    File file = File.fromUri(Uri.parse(trainingData[i]));
    final bytes = await file.readAsBytes();
    final archiveFile = ArchiveFile('trainingData', bytes.length, bytes);

    archive.addFile(archiveFile);
  }

I keep getting the error message: "Cannot extract a file path from a https URI," so I'm trying to figure out if I should download the files from Firebase to the local storage of the app to then work that code on the images OR I should just skip uploading the images to Firebase in the first place and just have the images the user uploads be loaded locally so they can be added to a zip file with the above for loop. Please help me fix this function to create a zip file with the images retrieved from a link in Firebase.

0

There are 0 best solutions below