Reputation: 31
I use image_picker: ^0.8.5+3
for upload image in web flutter.
Future _imgFromGallery() async {
final image = await picker.pickImage(
source: ImageSource.gallery, maxWidth: 800, maxHeight: 800);
}
But when I print image.path
the uploaded photo, it shows me this address with 'blob' blob 'http://localhost:22808/8108f482-37c1-4b7f-9e9c-9e65d1810f5a'
I want to convert image to base64
and for this I use the following code. But this conversion is not done correctly and completely.Can you help me in this matter?
final bytes = html.File(image.path.codeUnits, image.path);
Uint8List b = Uint8List(bytes.toString().length);
String img64 = Base64Encoder().convert(b);
Upvotes: 1
Views: 3283
Reputation: 31
I found the solution to my problem. I had to add the image_picker_for_web: ^2.1.8
and convert the photo to Base64
with the code below:
var image = await picker.pickImage(
source: ImageSource.gallery, maxWidth: 800, maxHeight: 800);
var imageForWeb = await image.readAsBytes();
String base64Image = base64Encode(imageForWeb);
Upvotes: 2