1

I've been struggling with this error for past few days, and I can't seem to find any useful answers online, so any help would be much appreciated!

I'm working with Flutter Web, and I am using universal_io package due to dart:io not being supported on the web. With help of an Image package I am converting file from Jpg to Png and am trying to convert recieved Unit8List of an converted file to an File variable. However that doesn't seem to work.

I KEEP GETTING THIS ERROR:

Error: FormatException: Unexpected extension byte (at offset 0)

Full error screenshot

WHAT I'M DOING:
I am trying to convert an Unit8List to an File Variable with this line:
File convertedFile = File.fromRawPath(png); with png being an Unit8List.

FULL CODE:

convertFiles() async {
  //1. Requesting file from the internet [✓ works]
  http.Response response = await http.get(
    Uri.parse(folderFiles[openFileIndex.value]["link"]),
  );

  //2. Decoding WEBP image with "Image" package [✓ works]
  var image = img.decodeWebP(response.bodyBytes);

  //3. Encoding decoded WEBP file as an PNG [✓ works]
  Uint8List png = img.encodePng(image!) as Uint8List;

  //4. Trying to convert file bytes(Unit8List) to a File Variable [✗ throws an error]
  File convertedFile = File.fromRawPath(png);
}

VSCode Screenshot

WHAT I TRIED:
I've tried everything I've seen on the internet including moving to Master channel and Upgrading Flutter, but none of those things solved the problem.

FLUTTER DOCTOR:

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.5.0-4.0.pre.23, on macOS 12.6 21G115 darwin-arm64, locale en-SI)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 14.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2021.3)
[✓] VS Code (version 1.71.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

• No issues found!

Terminal Screenshot
Nik Grmek
  • 31
  • 2

1 Answers1

0

This is an issue related to the universal.io package, there is already an opened issue, you can track the progress here - Flutter Web : Unable to convert uint8list to File.

Meanwhile you can check is this constructor can help you - Image.memory

Vladimir Gadzhov
  • 273
  • 2
  • 10
  • Hey, thanks for replying so fast! I've already tried Image.memory and it works great at what it's supposed to do, but I couldn't find a way to convert that image to a File so that I can upload it to Firebase Storage. Is that conversion even possible? – Nik Grmek Oct 09 '22 at 13:12
  • 1
    Hey @NikGrmek you can use upload raw data [link](https://firebase.google.com/docs/storage/flutter/upload-files#uploading_raw_data), so you can skip the conversion. – Vladimir Gadzhov Oct 09 '22 at 13:59