firebase获取图片网址

时间:2017-09-13 14:02:16

标签: android firebase firebase-storage

我正在将图像从本地存储上传到firebase,虽然我的代码我想获取上传的图片网址并将其存储到字符串中。我怎么能这样做?

        StorageReference filepath1 = mStorage.child("Blog_Image").child(mcontentURI.getLastPathSegment() + random());

        final String c;
        filepath1.putFile(mcontentURI).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {

            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                final Uri downlaodUrl = taskSnapshot.getDownloadUrl();
                String b = downlaodUrl.toString();
                c = b;

            }

        });

1 个答案:

答案 0 :(得分:0)

尝试以下更改。它应该工作:

StorageReference filepath1 = mStorage.child("Blog_Image").child(mcontentURI.getLastPathSegment() + random());
    public static String c;
    filepath1.putFile(mcontentURI).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
        @Override
        public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
            String b = taskSnapshot.getDownloadUrl().toString();
            c = b;
        }
    });