I'm using flutter web. I'm trying to upload an image using image_picker and store in firebase storage. The image_picker returns PickedFile type. So, I'm converting it to File type using File image = File(pickedFile.path) and then upload using ref.putFile(image). But the file doesn't get uploaded. I'm getting a Namespace exception. Any ideas?
PickedFile pickedFile =
await picker.getImage(source: ImageSource.gallery);
File newFile = File(pickedFile.path);
var now = DateTime.now().millisecondsSinceEpoch;
StorageReference reference =
FirebaseStorage.instance.ref().child("images/$now");
StorageUploadTask uploadTask = reference.putFile(newFile);
//Upload the file to firebase
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
// Waits till the file is uploaded then stores the download url
String url = await taskSnapshot.ref.getDownloadURL();
The error I'm getting is
Error: Unsupported operation: _Namespace
at Object.throw_ [as throw] (http://localhost:64148/dart_sdk.js:4322:11)
at Function.get _namespace [as _namespace] (http://localhost:64148/dart_sdk.js:54027:17)
at io._File.new.existsSync (http://localhost:64148/dart_sdk.js:51618:51)
at firebase_storage.StorageReference.__.putFile (http://localhost:64148/packages/firebase_storage/firebase_storage.dart.lib.js:701:27)
at add_product$46view._AddProductPageState.new.loadAssets (http://localhost:64148/packages/ecommerce_glasses/product/views/add_product.view.dart.lib.js:1234:38)
at loadAssets.next (<anonymous>)
at http://localhost:64148/dart_sdk.js:37211:33
at _RootZone.runUnary (http://localhost:64148/dart_sdk.js:37065:58)
at _FutureListener.thenAwait.handleValue (http://localhost:64148/dart_sdk.js:32049:29)
at handleValueCallback (http://localhost:64148/dart_sdk.js:32596:49)
at Function._propagateToListeners (http://localhost:64148/dart_sdk.js:32634:17)
at _Future.new.[_completeWithValue] (http://localhost:64148/dart_sdk.js:32477:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:64148/dart_sdk.js:32499:35)
at Object._microtaskLoop (http://localhost:64148/dart_sdk.js:37326:13)
at _startMicrotaskLoop (http://localhost:64148/dart_sdk.js:37332:13)
at http://localhost:64148/dart_sdk.js:32851:9