小编Koz*_*ero的帖子

无法使用 Flutter 将文件上传到 FirebaseStorage

我在将 File 对象形式的 jpg 图像上传到 FirebaseStorage 时遇到问题。错误发生在这一行StorageUploadTask uploadTask = reference.putFile(image)。我到处搜索都没有找到任何有关的信息Unhandled Exception: PlatformException

代码:

  void uploadAd({File image,int price, String name,String desc,String location,String category}) async{ 
  print(image.path);
  String userid = await UserData().getId();
  FirebaseStorage _storage = FirebaseStorage.instance;
  StorageReference reference = _storage.ref();
  StorageUploadTask uploadTask = reference.putFile(image);  //Error occurs on this line
  var refurl =  (await uploadTask.onComplete).ref.getDownloadURL();
  print(refurl);
  String url = refurl.toString();
  String productid = Uuid().v4();
  Firestore.instance.collection('products').add({'product_id': productid, 'user_id': userid,'name':name,'price':price,'location':location,'category':category,'primary_image':url,'description':desc});
}
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪

I/flutter (25579): before upload function /storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20191228-WA0000.jpg <-- path of …
Run Code Online (Sandbox Code Playgroud)

android dart firebase flutter firebase-storage

2
推荐指数
1
解决办法
2509
查看次数

标签 统计

android ×1

dart ×1

firebase ×1

firebase-storage ×1

flutter ×1