Flutter Web How to Convert Uint8List to File
Asked Answered
M

1

7

I am having trouble on converting Uint8List image to File on flutter web since dart:io is not supported on the web, i need it to be file in order to upload it to FirebaseStorage, is there any workaround for this ? thankyou

Middle answered 4/5, 2021 at 11:21 Comment(0)
T
8

Since dart:io isn't avalible on web, you can use the universal_io package.

Add it to your pubspec.yaml.

import 'package:universal_io/io.dart';

File createFileFromBytes(Uint8List bytes) => File.fromRawPath(bytes);
Tholos answered 4/5, 2021 at 16:23 Comment(7)
isnt dart : io not supported on flutter-web?Middle
Yes, you are right. dart:io isn't avalibe on web, but you can use the universal_io package.Tholos
ah thankyou i dont know that package exist, will accept your answer after i tried itMiddle
Okay, here is the package on pub: pub.dev/packages/universal_ioTholos
For me, this returns Error: FormatException: Unexpected extension byte (at offset 0). There are several similar issues reported and the author has yet to reply to any of them.Popham
This is not the answer, this uses the Uint8List as the file path, not the actual contentsUnscrupulous
Error: FormatException: Missing extension byte (at offset 402) Any solution?Privileged

© 2022 - 2024 — McMap. All rights reserved.