[英]Storing images to firebase storage
我正在嘗試將從谷歌下載的圖像存儲到 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;
}
}
}
我認為問題出在這里:
imageUri = Uri.fromFile(new File("images"));
這表示您有一個名為images
的文件,然后您想要將其上傳到 Firebase。您收到的錯誤消息表明找不到這樣的文件:
E/UploadTask:找不到要上傳的文件:file:///images
我建議檢查:
此搜索的更多內容: https://stackoverflow.com/search?tab=votes&q=%5android%5d%5bjava%5d%20read%20local%20file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.