I'm trying to store an image that I downloaded from google to firebase storage I'm not really sure what I'm doing wrong.
I'm getting this error " An unknown error occurred, please check the HTTP result code and inner exception for server response. "
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)
this my code:
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();
}
});
}
}
Storage Rules:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write: if true;
}
}
}
I think the problem is here:
imageUri = Uri.fromFile(new File("images"));
This says that you have a file called images
, which you then want to upload to Firebase. The error message you get indicates that no such file can be found:
E/UploadTask: could not locate file for uploading:file:///images
I recommend checking out:
And more from this search: https://stackoverflow.com/search?tab=votes&q=%5bandroid%5d%5bjava%5d%20read%20local%20file
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.