使用Java Rest API从Firebase存储中的上传文件中获取公共下载URL [英] Get public download URL from uploaded file in firebase storage with Java rest API
问题描述
我想从firebase-admin sdk for Java上传的文件(Blob)中获取下载URL.
我的代码:
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("...")
.build();
FirebaseApp app = FirebaseApp.initializeApp(options);
StorageClient storage = StorageClient.getInstance(app);
Bucket bucket = storage.bucket("...");
Blob blob = bucket.create(...);
因此,通过此代码,我可以将文件上传到Firebase存储中. 但我不知道如何获取下载URL. 我想获取URL( https://firebasestorage.googleapis.com .. .)>
但是方法blob.getMediaLink() 向我返回URL( https://www.googleapis.com/download/storage...)是私有的
您可以创建 Blob.signUrl().
I would like to get the download URL from a file (Blob) upload by firebase-admin sdk for java.
My Code:
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("...")
.build();
FirebaseApp app = FirebaseApp.initializeApp(options);
StorageClient storage = StorageClient.getInstance(app);
Bucket bucket = storage.bucket("...");
Blob blob = bucket.create(...);
so, by this code I am able to upload file in firebase storage. But I dont know how to get the download URL.. I want to get the URL (https://firebasestorage.googleapis.com...)
But the method blob.getMediaLink() returns me the URL (https://www.googleapis.com/download/storage...) which is private
You can create a signed URL, which does essentially the same thing as the download URLs generated by Firebase client SDKs, using Blob.signUrl().
这篇关于使用Java Rest API从Firebase存储中的上传文件中获取公共下载URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!