![](/img/trans.png)
[英]firebase_storage/object-not-found No object exists at the desired reference
[英]firebase_storage object-not-found No object exists at the desired reference flutter
重要提示:我发现了同样的问题,但由于调试信息不完整而关闭。
我正在将图像上传到 firebase 存储,然后获取该图像的下载 URL 并将其存储到 firebase,这样我就可以使用该 URL 来显示用户的个人资料图像 using.network 图像。
在我像这样存储图像之前它工作正常
Reference storageRef = FirebaseStorage.instance.ref('images');
file = await _compressImage(file: file,);
await storageRef.putFile(file);
final String downloadUrl = await storageRef.child(id).getDownloadURL();
return downloadUrl;
但是在我将图像存储在特定文件夹中之后
Reference storageRef = FirebaseStorage.instance.ref('images');
file = await _compressImage(file: file, id: id);
await storageRef
.child(Get.find<UserController>().user.username)
.child(id)
.putFile(file);
final String downloadUrl = await storageRef.child(id).getDownloadURL();
return downloadUrl;
它显示此错误。
[firebase_storage/object-not-found] No object exists at the desired reference.
这是可解释的代码:我将可下载的 URL 存储在 newImage 变量中
String newImage;
if (_controller.file != null) {
newImage = await Database().uploadFile(
file: _controller.file,
id: Get.find<UserController>().user.username);
print("new image: " + newImage.toString());
}
但是在这里,当我打印 newImage 的值时,它正在打印null到控制台。
new image: null
这是将图像上传到 firebase 存储的第二种方法。
Future<String> uploadFile({@required File file, @required String id}) async {
try {
file = await _compressImage(file: file, id: id);
await storageRef
.child(Get.find<UserController>().user.username)
.child(id)
.putFile(file);
final String downloadUrl = await storageRef.child(id).getDownloadURL();
return downloadUrl;
} catch (e) {
print(e);
}
}
调试控制台:
E/StorageException(11376): StorageException has occurred.
E/StorageException(11376): Object does not exist at location.
E/StorageException(11376): Code: -13010 HttpResult: 404
E/StorageException(11376): { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}
E/StorageException(11376): java.io.IOException: { "error": { "code": 404, "message": "Not Found. Could not get object", "status": "GET_OBJECT" }}
E/StorageException(11376): at com.google.firebase.storage.network.NetworkRequest.parseResponse(NetworkRequest.java:434)
E/StorageException(11376): at com.google.firebase.storage.network.NetworkRequest.parseErrorResponse(NetworkRequest.java:451)
E/StorageException(11376): at com.google.firebase.storage.network.NetworkRequest.processResponseStream(NetworkRequest.java:442)
E/StorageException(11376): at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:272)
E/StorageException(11376): at com.google.firebase.storage.network.NetworkRequest.performRequest(NetworkRequest.java:286)
E/StorageException(11376): at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:70)
E/StorageException(11376): at com.google.firebase.storage.internal.ExponentialBackoffSender.sendWithExponentialBackoff(ExponentialBackoffSender.java:62)
E/StorageException(11376): at com.google.firebase.storage.GetDownloadUrlTask.run(GetDownloadUrlTask.java:76)
E/StorageException(11376): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
E/StorageException(11376): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
E/StorageException(11376): at java.lang.Thread.run(Thread.java:764)
I/flutter (11376): [firebase_storage/object-not-found] No object exists at the desired reference.
I/flutter (11376): new image: null
但是当我检查 firebase 存储并且图像在那里成功上传时。
我所知道的是图像已成功上传到 firebase 存储,但上述方法在上传图像之前以某种方式返回可下载的 URL。
我因为与您和 IDK 相同的问题而浪费了很多时间,但它是通过在使用它之前创建参考来工作的:
final FirebaseStorage feedStorage =
FirebaseStorage.instanceFor(bucket: F.feedBucket);
Reference refFeedBucket = feedStorage
.ref()
.child('venues')
.child(auth.user.uid)
.child('vibes')
.child(p.basename(file.path));
String downloadUrl;
TaskSnapshot uploadedFile = await refFeedBucket.putFile(file);
if (uploadedFile.state == TaskState.success) {
downloadUrl = await refFeedBucket.getDownloadURL();
}
return downloadUrl;
对我有用的东西有点出乎意料。 首先,我有这样的代码,有多少例子。
Reference reference = storage.ref(filePath);
UploadTask uploadTask = reference.putFile(imageToUpload);
final storageSnapshot = uploadTask.snapshot;
final downloadUrl = await storageSnapshot.ref.getDownloadURL();
然后,我决定玩弄它。 我注意到如果我等待 putFile 调用,它会更改返回类型,即使它不是未来。
Reference reference = storage.ref(filePath);
final TaskSnapshot snapshot = await reference.putFile(imageToUpload);
final downloadUrl = await snapshot.ref.getDownloadURL();
你知道吗,这行得通,非常奇怪。 考虑到这并不明显,您可以等待 putFile 调用。
我们是这样做的
Reference ref = FirebaseStorage.instance
.ref()
.child('user_Image')
.child('${authResult.user?.uid}.jpg');
UploadTask uploadTask = ref.putFile(imageUser);
final snapshot = await uploadTask.whenComplete(() => null);
final urlImageUser = await snapshot.ref.getDownloadURL();
试试这个从 firebase 加载图像
Future<String> downloadedUrl(String imageName) async {
String downloadedUrl =
await storage.ref('$imageName').getDownloadURL();
return downloadedUrl;
}
就我而言,我在路径上弄错了单词大小写。
Firebase 存储Case sensitive
请检查一下!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.