Skip to content

FLUTTER WEB - Error: FormatException: Unexpected extension byte (at offset 0) #113180

@NikGrmek

Description

@NikGrmek

Hey Everyone! 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 selected image from Jpg to Png and am trying to convert recieved Unit8List of an converted image to an File variable. However converting Unit8List to File doesn't seem to work.

I KEEP GETTING THIS ERROR:
Error: FormatException: Unexpected extension byte (at offset 0)

Full Error:
image

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 [✗ error]   
    File convertedFile = File.fromRawPath(png); 
}

VSCode screenshot:
code

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    r: timeoutIssue is closed due to author not providing the requested details in time

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions