【发布时间】:2020-11-20 18:18:41
【问题描述】:
我正在使用颤振网络。我正在尝试使用 image_picker 上传图像并存储在 firebase 存储中。 image_picker 返回 PickedFile 类型。因此,我使用 File image = File(pickedFile.path) 将其转换为文件类型,然后使用 ref.putFile(image) 上传。但是文件没有上传。我得到一个命名空间异常。有什么想法吗?
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();
我得到的错误是
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
【问题讨论】:
标签: firebase flutter firebase-storage flutter-web