我正在创建一个用户在Firebase存储上上传图片的应用。上传图像后,我想将图像的URL和其他详细信息上传到我自己的API。我如何获得用户刚刚上传的该图像的Uri。 This教程教授如何进行上传,但未说明如何获取图片网址。我尝试了所有的教程,但都没有显示我想要的东西。
答案 0 :(得分:3)
答案 1 :(得分:1)
您将获得onSuccess回调的下载URL。请检查以下代码
public static void storeInFirebase(Context context, Uri uri, String type) {
StorageReference riversRef = null;
mStorageRef = FirebaseStorage.getInstance().getReference();
//to create a separate folder with all the pictures uploaded
riversRef = mStorageRef.child("pictures/" + "unique_value");
UploadTask uploadTask = riversRef.putFile(uri);
uploadTask.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
DialogUtils.dismissProgressDialog();
// 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.
downloadUrl = taskSnapshot.getDownloadUrl();
Log.d("downloadUrl", "" + downloadUrl);
}
});
}
答案 2 :(得分:0)
imagename.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
insertDataFirebase_with_image(UID, String.valueOf(uri));
insertData_with__Image(UID, String.valueOf(uri));
}
});
//这里imagename是导致映像位置的StoragePreference //无用插入数据是我用来将图像URL存储到我的实时数据库中的功能