如何使用firebase实时获取上传文件的link?
How to get the link of uploaded file using firebase in realtime?
我正在使用 firebase 存储来上传文件。代码是:
StorageReference storageRef = storage.getReferenceFromUrl("gs://fir-896a6.appspot.com");
final Uri selectedFile = data.getData();
StorageReference uploadRef = storageRef.child(selectedFile.getLastPathSegment());
UploadTask uploadTask = uploadRef.putFile(selectedFile);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.i("Success", "uploaded");
}
}
上传文件成功。现在上传完成后,我想要指向该文件的两个链接(例如 https://firebasestorage.googleapis.com/v0/b/fir-896a6.appspot.com/o/17992?alt=media&token=68bd978a-4def-40d8-8edb-6526a15a94e3
和
gs://fir-896a6.appspot.com/17992) 实时(可能在 onSuccessListener 上)
来自我博客的一个简单代码片段:Firebase Storage
...
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
hideProgressDialog();
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Log.d("MainActivity", downloadUrl.toString());
showAlertDialog(MainActivity.this, "Upload Complete", downloadUrl.toString(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
findViewById(R.id.button_step_3).setEnabled(false);
findViewById(R.id.button_step_4).setEnabled(true);
}
});
Glide.with(MainActivity.this)
.load(downloadUrl)
.into(mImageView);
}
})
...
我正在使用 firebase 存储来上传文件。代码是:
StorageReference storageRef = storage.getReferenceFromUrl("gs://fir-896a6.appspot.com");
final Uri selectedFile = data.getData();
StorageReference uploadRef = storageRef.child(selectedFile.getLastPathSegment());
UploadTask uploadTask = uploadRef.putFile(selectedFile);
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.i("Success", "uploaded");
}
}
上传文件成功。现在上传完成后,我想要指向该文件的两个链接(例如 https://firebasestorage.googleapis.com/v0/b/fir-896a6.appspot.com/o/17992?alt=media&token=68bd978a-4def-40d8-8edb-6526a15a94e3 和 gs://fir-896a6.appspot.com/17992) 实时(可能在 onSuccessListener 上)
来自我博客的一个简单代码片段:Firebase Storage
...
uploadTask.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
hideProgressDialog();
Uri downloadUrl = taskSnapshot.getDownloadUrl();
Log.d("MainActivity", downloadUrl.toString());
showAlertDialog(MainActivity.this, "Upload Complete", downloadUrl.toString(), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
findViewById(R.id.button_step_3).setEnabled(false);
findViewById(R.id.button_step_4).setEnabled(true);
}
});
Glide.with(MainActivity.this)
.load(downloadUrl)
.into(mImageView);
}
})
...