将图像表单android上传到Firebase后如何获取图像URL? [英] How to Get Image URL after uploading an image form android to Firebase?

查看:98
本文介绍了将图像表单android上传到Firebase后如何获取图像URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个用户将图像上传到Firebase存储上的应用程序.上载图像后,我想将图像的URL和其他详细信息上载到我自己的API.我如何获取用户刚刚上传的图像的Uri. 教程教了如何做上传,但未显示如何获取图片网址.我尝试了所有教程,但没有一个显示我想要的东西.

I am making an App that user uploaded images on Firebase storage. After Uploading the image i want to upload the Images's URL and other details to my own API. How can i get the Uri of that image which the user just uploaded. This tutorial teaches how to do the uploading but doesn't show how to get the image URL. I tried all the tutorials but none shows the thing that i want.

推荐答案

根据文档,则可以在.onSuccessListener中调用.getDownloadUrl来获取图像URL.

According to the documentation, you can call .getDownloadUrl in the .onSuccessListener to get the image URL.

以下是文档中的示例:

// Get the data from an ImageView as bytes
imageView.setDrawingCacheEnabled(true);
imageView.buildDrawingCache();
Bitmap bitmap = imageView.getDrawingCache();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] data = baos.toByteArray();

UploadTask uploadTask = mountainsRef.putBytes(data);
uploadTask.addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle unsuccessful uploads
    }
}).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
        // taskSnapshot.getMetadata() contains file metadata such as size, content-type, and download URL.
        Uri downloadUrl = taskSnapshot.getDownloadUrl();
    }
});

这篇关于将图像表单android上传到Firebase后如何获取图像URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆