简体   繁体   English

将图像上传到 firebase 时,无论我做什么,这个错误总是出现

[英]while uploading image to firebase, this one error is always comes whatever i do

在此处输入图像描述

what went wrong?什么地方出了错? even if i replace the XFile into File, same error comes at this putFile.即使我将 XFile 替换为文件,此 putFile 也会出现同样的错误。

try this convert that xfile to file尝试将 xfile 转换为文件

uploadImages(XFile? pathsw) async {
    final paths = path.basename(pathsw!.path);
    final pathStorage =
        "${NAMEFOLDER}/${PATHNAME}/$paths";
   /// Start looking from here then so on
    final file = File(pathsw.path);
    final reference = FirestoreService.storage.ref().child(pathStorage);
    final task = reference.putFile(file);
    final snap = await task.whenComplete(() {});
    final url = await snap.ref.getDownloadURL();
    return url;
  }

If you see, .putFile() takes in a element of File type.如果您看到, .putFile()接受一个File类型的元素。 And you're accepting of type XFile .您正在接受XFile类型。 To convert:转换:

File uploadImage = File(image!.path)

now the best way to upload would be to use .putFile() or .putData()现在最好的上传方式是使用.putFile().putData()

Your .putFile() implementation looks great, if you want to use .putData() , find the following code:您的.putFile()实现看起来很棒,如果您想使用.putData() ,请找到以下代码:

await reference.putData(uploadImage.readAsBytesSync())

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在上传图像抖动时显示小部件(加载 20%,30%) - How do I display a widget ( Loading 20%,30%) while uploading an image flutter Flutter - 将图像上传到 Firebase 存储 - Flutter - Uploading Image to Firebase Storage 将图像上传到 firebase 的任何解决方案? - Any solution for uploading an image to firebase? 在实施 firebase 时出现此错误时该怎么办 - What to do in this error in flutter while implementing firebase 将应用程序上传到 TestFlight 时出错我该如何解决? - Error uploading app to TestFlight what do I do to fix it? 将日期数据上传到 flutter 中的 firestore 时出现错误 - I am getting error while uploading date data to firestore in flutter 如何在使用 firebase 和 flutter 登录和注册时发现身份验证错误? - How do i catch error of authentication while logging in and signup using firebase and flutter? 在上传到 Firebase 存储之前,您是否必须知道图像文件类型? - Do you have to know the image file type before uploading to Firebase Storage? 如何在不从我的应用上传图像的情况下将图像 URL 从 Firebase 存储获取到 Firebase 数据库? - How can i get Image URL from Firebase Storage to Firebase Database without uploading image from my app? 在向 email 注册时将用户头像图像上传到 firebase 时,在使用 getter 获取 ImageUrl 时会给出 null 值 - While uploading user avatar image to firebase while registering with email gives null value when using getter to get ImageUrl
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM