As the title say, I am trying to upload a image to firebase storage and get its download URL. I have tried every code in internet found but nothing works. Can you help me please ?
Thank you very much !
Here is my code, the task is Always onFailure:
private void loadPhoto (Bitmap imageBitmap){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] data = baos.toByteArray();
StorageReference ref = screenshotRef.child("Project_Screenshots/" + input.getText().toString() + ".png");
//UploadTask uploadTask = screenshotRef.putBytes(data); // is the photo converted
ref.putBytes(data)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
// Get a URL to the uploaded content
url_screenshoot = taskSnapshot.getMetadata().getName();
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// Handle unsuccessful uploads
// ...
}
});
}
my gradle:
implementation 'com.google.firebase:firebase-firestore:17.1.2'
implementation 'com.google.firebase:firebase-storage:19.1.0'
implementation 'com.google.firebase:firebase-core:17.2.1'