Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
292 views
in Technique[技术] by (71.8m points)

android - How to get file URL after uploading them to Firebase?

Once you have uploaded a file to Firebase how can you get it's URL so that you can store that for later use? I want to write the URL to a Firebase Database so that other users can access the image.

I am uploading the file like so:

public void uploadFile()
{

    StorageReference filepath = mstorageRef.child("folder").child(filename);

    Uri File= Uri.fromFile(new File(mFileName));

    filepath.putFile(File).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot)
        {
            Toast.makeText(MtActivity.this, "Upload Done", Toast.LENGTH_LONG).show();
        }
    });
}

I have confirmed that the files are in fact uploading so now I just need the URL which I can write to my Database. However when I tried to do this:

Uri downloadUrl = taskSnapshot.getMetadata().getDownloadUrl();

It gives me an error and says This method should only be accessed from tests or within private scope

I'm not sure what that means and I also don't know why I would be getting that error since I'm following this example provided by Firebase.

Is there a new way of getting the URL?

Also, is that URL unique to that item in particular? Meaning if I store it to a database and try to access it later will I be able to do so?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...