【发布时间】:2021-10-18 09:56:37
【问题描述】:
所以我想上传封面照片如果用户选择或个人资料图片如果选择保存btn点击
这是我的 UI 设计,以便更好地理解。
为了从图库中选择图片,我做了这样的事情:
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.个人资料)
【问题讨论】:
-
这是获取已上传到 Firebase 存储的图片的 download URL 的方式。
-
@AlexMamo 你是对的,但在我的情况下,我怎样才能做到这一点,或者我想要两个上传到图像,并且两者的 URL 都应该上传到 Firestore。请帮忙。
-
创建两个单独的存储添加操作。
-
@AlexMamo 我会试试的
-
好的,试一试,告诉我它是否有效。
标签: java android google-cloud-firestore google-cloud-storage