我试图存储从google下载到firebase存储的图片,但我不太确定自己做错了什么。
我得到这个错误“发生了一个未知的错误,请检查HTTP结果代码和服务器响应的内部异常。。”
E/UploadTask: could not locate file for uploading:file:///images
E/StorageException: StorageException has occurred.
An unknown error occurred, please check the HTTP result code and inner exception for server response.
Code: -13000 HttpResult: 0
E/StorageException: /images: open failed: ENOENT (No such file or directory)
java.io.FileNotFoundException: /images: open failed: ENOENT (No such file or directory)这是我的代码:
private void saveImgToStorage() {
if (imageUri != null) {
imageUri = Uri.fromFile(new File("images"));
imgRef = storageReference.child("images");
imgRef.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot > () {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(getContext(), "STORED IMAGE", Toast.LENGTH_SHORT).show();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(getContext(), "FAILED TO STORE IMAGE " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}储存规则:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}发布于 2022-05-05 14:36:20
我认为问题在于:
imageUri = Uri.fromFile(new File("images"));这表明您有一个名为images的文件,然后要将该文件上载到Firebase。您得到的错误消息表明找不到这样的文件:
File:///images E/UploadTask:无法找到上传文件:
我建议退房:
更多信息来自于这个搜索:https://stackoverflow.com/search?tab=votes&q=%5bandroid%5d%5bjava%5d%20read%20local%20file
https://stackoverflow.com/questions/72122821
复制相似问题