[英]while uploading image to firebase, this one error is always comes whatever i do
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.