You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know flutter web is still fresh but i'm trying to do image uploading in my flutter web project, so image_picker is still not supported but i'm looking for suggestions for any replacements or approaches for that.
I'm using firebase, and the part that i can't figure out is how to pick an image from my computer to upload it.
Thanks!
Reacted by Paul Iluhin, guit4eva, Zangetsu0, Sacchi, David Iglesias, Fahim Shariar Shoumik, Praharsh Bhatt, januwA, Benjamin Le Forestier, mono — Masayuki Ono and 52 more
Reacted by guit4eva, Saif Allah Khaled, Alexander Matsko, appstute-sachin, jobsyNZ, Vivekkumar Dhakad, Rody Davis, Radosław, shinriyo, Vinicius Sossella and 1 more
Of course, you can tweak this according to your needs by changing the returned object (ex: File itself instead of reading it) and using a different reader.readAs* function.
Seeing that almost all Firebase plugins for Flutter depend on the Flutter package, I don't think you can use the Flutter package. Try to see if you can use the Web one instead
Reacted by Paul Iluhin, Eunomia Dev, Fahim Shariar Shoumik, Mohamed Ali, Mariano Zorrilla, Constantin Stan, Olfat, David Iglesias, Khamchunovog, Thathy916 and 20 more
Reacted by Eunomia Dev, SARAVANAN ANAND, 韩帅虎, Ben Miner and Cuieney
Have you implemented the function of uploading the flutter web image? The image upload function I made can't be used on the mobile browser, except for chrome. What's the matter?
Have you implemented the function of uploading the flutter web image? The image upload function I made can't be used on the mobile browser, except for chrome. What's the matter?
I am facing the same issue. @Thathy916 Did you find any solution?
I finally found the solution which probably works on mobile safari too. I leave it here. Hope it will help someone like me until image_picker adds support for web.
Future<void> _setImage() async {
final completer = Completer<List<String>>();
InputElement uploadInput = FileUploadInputElement();
uploadInput.multiple = true;
uploadInput.accept = 'image/*';
uploadInput.click();
//* onChange doesn't work on mobile safari
uploadInput.addEventListener('change', (e) async {
// read file content as dataURL
final files = uploadInput.files;
Iterable<Future<String>> resultsFutures = files.map((file) {
final reader = FileReader();
reader.readAsDataUrl(file);
reader.onError.listen((error) => completer.completeError(error));
return reader.onLoad.first.then((_) => reader.result as String);
});
final results = await Future.wait(resultsFutures);
completer.complete(results);
});
//* need to append on mobile safari
document.body.append(uploadInput);
final List<String> images = await completer.future;
setState(() {
_uploadedImages = images;
});
uploadInput.remove();
}
This also works:
Future<void> _setImage() async {
final completer = Completer<List<String>>();
final InputElement input = document.createElement('input');
input
..type = 'file'
..multiple = true
..accept = 'image/*';
input.click();
onChange doesn't work in mobile safari
input.addEventListener('change', (e) async {
final List<File> files = input.files;
Iterable<Future<String>> resultsFutures = files.map((file) {
final reader = FileReader();
reader.readAsDataUrl(file);
reader.onError.listen((error) => completer.completeError(error));
return reader.onLoad.first.then((_) => reader.result as String);
});
final results = await Future.wait(resultsFutures);
completer.complete(results);
});
document.body.append(input);
// input.click(); can be here
final List<String> images = await completer.future;
setState(() {
_uploadedImages = images;
});
input.remove();
}
Reacted by drdevinhopkins, akippa-sumimoto, isomi, Daiki Sumimoto, FulingFan-1, Wilson Lau and Aha
Of course, you can tweak this according to your needs by changing the returned object (ex: File itself instead of reading it) and using a different reader.readAs* function.
Seeing that almost all Firebase plugins for Flutter depend on the Flutter package, I don't think you can use the Flutter package. Try to see if you can use the Web one instead
I get this error on console:
File chooser dialog can only be shown with a user activation.
Because image_picker_platform_interface >=1.1.0 depends on http ^0.12.1 and andu depends on http 0.12.0+4, image_picker_platform_interface >=1.1.0 is forbidden.
Of course, you can tweak this according to your needs by changing the returned object (ex: File itself instead of reading it) and using a different reader.readAs* function.
Seeing that almost all Firebase plugins for Flutter depend on the Flutter package, I don't think you can use the Flutter package. Try to see if you can use the Web one instead
This solution works if we have to select a file. But when the file picker opens, and we cancel the dialog. This code won't run again. It keeps waiting for the file to be picked which was cancelled long back.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
ferhatb commentedon Jul 16, 2019
/cc @hterkelsen: would require hosting file input for upload and ability to click to run picker.
aabounegm commentedon Jul 24, 2019
You can try this code as a workaround until plugins are supported by Flutter Web. It worked with me.
Edit: here is a sample function that wraps it in a Future:
or in case you want only one file:
Of course, you can tweak this according to your needs by changing the returned object (ex:
Fileitself instead of reading it) and using a differentreader.readAs*function.Seeing that almost all Firebase plugins for Flutter depend on the Flutter package, I don't think you can use the Flutter package. Try to see if you can use the Web one instead
aggmoulik commentedon Sep 11, 2019
I really love to work on the plugin.. Does anyone working on it?
Please tell me how to start creating plugin.
harryterkelsen commentedon Sep 11, 2019
@ditman has been working on a prototype for image_picker
ditman commentedon Sep 13, 2019
Thathy916 commentedon Oct 18, 2019
Have you implemented the function of uploading the flutter web image? The image upload function I made can't be used on the mobile browser, except for chrome. What's the matter?
[-]Image picker flutter web[/-][+][image_picker] Add support for web[/+]ykaito21 commentedon Dec 18, 2019
I am facing the same issue. @Thathy916 Did you find any solution?
ykaito21 commentedon Dec 19, 2019
I finally found the solution which probably works on mobile safari too. I leave it here. Hope it will help someone like me until image_picker adds support for web.
This also works:
19 remaining items
bytejutsu commentedon Jun 1, 2020
ditman commentedon Jun 1, 2020
@DhiaEddineNabli sorry I hid your comment, that's not the package we're working on. The official package is going to be:
image_picker_for_web
ditman commentedon Jun 4, 2020
Published
image_picker_for_webto pub.dev:https://pub.dev/packages/image_picker_for_web (^0.1.0)
For now, it is not endorsed, so you'll have to depend both on image_picker and image_picker_for_web. Please, see the instructions in the README.
ronytesler commentedon Aug 21, 2020
I get this error on console:
File chooser dialog can only be shown with a user activation.
shinriyo commentedon Sep 5, 2020
shinriyo commentedon Sep 5, 2020
need?
chaitanya-teja commentedon Sep 24, 2020
This solution works if we have to select a file. But when the file picker opens, and we cancel the dialog. This code won't run again. It keeps waiting for the file to be picked which was cancelled long back.
cedvdb commentedon Mar 18, 2021
why not include it directly in the image picker package ?
ditman commentedon Mar 18, 2021
image_picker default web support has been published recently.
https://pub.dev/packages/image_picker/changelog#073
image_picker has had web support (through an additional package:
image_picker_for_web) since version 0.6.7+1. Check it out here: https://pub.dev/packages/image_picker_for_webpumuckelo commentedon Mar 24, 2021
I got it working this way:
// file is PickedFile received by ImagePicker
pumuckelo commentedon Mar 24, 2021
Full working example function to use PickedFile with firebase storage
github-actions commentedon Aug 4, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.