当你调用时
getDownloadUrl(),该调用是异步的,你必须订阅成功回调以获取结果:
// Calls the server to securely obtain an unguessable download Urlprivate void getUrlAsync (String date){ // Points to the root reference StorageReference storageRef = FirebaseStorage.getInstance().getReference(); StorageReference dateRef = storageRef.child("/" + date+ ".csv"); dateRef.getDownloadUrl().addonSuccessListener(new OnSuccessListener<Uri>() { @Override public void onSuccess(Uri downloadUrl) { //do something with downloadurl } });}这将返回一个公开的,不可猜测的下载网址。如果你只是上传文件,则此公共网址将位于上传的成功回调中(上传后,你无需调用其他异步方法)。
但是,如果你只想String表示参考,则可以调用.toString()
// Returns a Uri of the form gs://bucket/path that can be used// in future calls to getReferenceFromUrl to perform additional// actionsprivate String niceReflink (String date){ // Points to the root reference StorageReference storageRef = FirebaseStorage.getInstance().getReference(); StorageReference dateRef = storageRef.child("/" + date+ ".csv"); return dateRef.toString();}


