【问题标题】:How to upload 2 images on firebase storage on click with URL in firestore如何通过点击 Firestore 中的 URL 在 Firebase 存储上上传 2 张图片
【发布时间】:2021-10-18 09:56:37
【问题描述】:

所以我想上传封面照片如果用户选择或个人资料图片如果选择保存btn点击 这是我的 UI 设计,以便更好地理解。

image desc

为了从图库中选择图片,我做了这样的事情:

    private void chooseImage(int imgReqCode) {
    // Defining Implicit Intent to mobile gallery
    Intent intent = new Intent();
    intent.setType("image/*");
    intent.setAction(Intent.ACTION_GET_CONTENT);
    startActivityForResult(
            Intent.createChooser(
                    intent,
                    "Select Image from here..."),
            imgReqCode);
}

这是 onActivityResult 代码:

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    checkAndSetImage(requestCode, COVER_IMG_REQUEST, resultCode, data, binding.coverPhoto, coverUri);
    checkAndSetImage(requestCode, PROFILE_IMG_REQUEST, resultCode, data, binding.profilePhoto, profileUri);
}

这是我的checkAndSetImage 方法:

private void checkAndSetImage(int requestCode, int PICK_IMAGE_REQUEST, int resultCode, Intent data, ImageView imageView, Uri filePath) {
    if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
        // Get the Uri of data
        filePath = data.getData();
        try {
            // Setting image on image view using Bitmap
            Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), filePath);
            imageView.setImageBitmap(bitmap);
        } catch (IOException e) {
            // Log the exception
            e.printStackTrace();
        }
    }

}

这是我的 Uri 声明为全局的:

private Uri coverUri, profileUri;

之后我很困惑如何将其上传到 firebase 存储并在我的 firestore 数据库中获取两者或哪个可用的 url

或根据您的说法,您如何根据我的布局在 firebase 数据库中上传 2 张图片(1.封面,2.个人资料)

image desc according to my layout

【问题讨论】:

  • 这是获取已上传到 Firebase 存储的图片的 download URL 的方式。
  • @AlexMamo 你是对的,但在我的情况下,我怎样才能做到这一点,或者我想要两个上传到图像,并且两者的 URL 都应该上传到 Firestore。请帮忙。
  • 创建两个单独的存储添加操作。
  • @AlexMamo 我会试试的
  • 好的,试一试,告诉我它是否有效。

标签: java android google-cloud-firestore google-cloud-storage


【解决方案1】:

您无法同时上传coverUriprofileUri 图片并期望同时完成上传。您需要做的是创建两个单独的上传,一旦上传 URL 可用,将其写入 Firestore。请查看下面如何获取 Java 中的下载 URL:

【讨论】:

  • 为什么不............
猜你喜欢
  • 2017-12-03
  • 1970-01-01
  • 1970-01-01
  • 2018-02-26
  • 1970-01-01
  • 2021-06-28
  • 1970-01-01
相关资源
最近更新 更多