Android 无法从Firebase存储检索图像:位置上不存在对象
我的应用程序有问题。我已将图像上载到Firebase存储,但现在无法检索它,我的错误是:Android 无法从Firebase存储检索图像:位置上不存在对象,android,firebase,firebase-storage,Android,Firebase,Firebase Storage,我的应用程序有问题。我已将图像上载到Firebase存储,但现在无法检索它,我的错误是: E/StorageException: StorageException has occurred. Object does not exist at location. Code: -13010 HttpResult: 404 我的代码如下所示: private void getImage() { mStorage = FirebaseStorage.getInstan
E/StorageException: StorageException has occurred.
Object does not exist at location.
Code: -13010 HttpResult: 404
我的代码如下所示:
private void getImage() {
mStorage = FirebaseStorage.getInstance("gs://bucket");
mStorageReference = mStorage.getReference().child("/animal_images/animals" + System.currentTimeMillis() + ".png");
final long ONE_MEGABYTE = 1024 * 1024;
mStorageReference.getBytes(ONE_MEGABYTE).addOnSuccessListener(bytes -> {
Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
DisplayMetrics displayMetrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
mImageView.setMinimumHeight(displayMetrics.heightPixels);
mImageView.setMinimumWidth(displayMetrics.widthPixels);
mImageView.setImageBitmap(bitmap);
}).addOnFailureListener(e -> Log.e("TAG", "Cannot load image" + e.getMessage()));
}
我检查了存储路径,一切正常,我做错了什么。任何建议。我认为问题在于您构建图像路径的方式:
mStorage.getReference().child("/animal_images/animals" + System.currentTimeMillis() + ".png");
当客户端请求映像时,该映像的当前时间戳似乎极不可能存在(System.currentTimeMillis()
)
在客户机中使用写入图像的时间戳是增加其文件名唯一性的好方法,但不能使用相同的方法来查找图像。您需要有某种方式将图像的时间戳从写入图像的客户端传送到读取图像的客户端。创建存储引用时:
mStorageReference=mStorage.getReference().child(“/animal_images/animals”+System.currentTimeMillis()+”.png”);
您编写了
System.currentTimeMillis()
,它的值不是常量,并且会不时更改。这意味着您基本上是在搜索一个由于时间变化而改变了值的名称。名称为新时间的图像不存在。这就是你找不到它的原因。嘿,埃拉多。下面有两个人试图帮助你。你查过他们的答案了吗?那之后你有什么进展吗?如果答案有用,请单击向上投票按钮(▲) 如果它回答了您的问题,请单击复选标记(✓) 接受它。这样其他人就知道你得到了(足够的)帮助。另请参见下面的Hey Eraldo。两个人试图帮助你。你检查了他们的答案吗?之后你有什么进展吗?如果答案有用,请单击向上投票按钮(▲) 如果它回答了您的问题,请单击复选标记(✓) 接受它。这样别人就会知道你已经得到了(足够的)帮助。也请参见