1

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'
adr1611
  • 31
  • 2
  • getDownloadURL is still available. The duplicate and its link to the documentation are clear about how to use it correctly. There is an old version that's deprecated, which you shouldn't use. Be sure to use the new instructions. – Doug Stevenson Jan 05 '20 at 18:36
  • Hello @DougStevenson, thank you for your answer but it does not help me very much since I have already consulted the link you gave me. Can you hepl me a bit more please ? – adr1611 Jan 05 '20 at 19:53
  • If you've already read that question and answer, then it's entirely unclear what you're stuck on. The other question shows you how to get a download URL for a file uploaded to Cloud Storage. – Doug Stevenson Jan 05 '20 at 19:54

0 Answers0