Home > Blockchain >  How to get downloadURL of uploaded file in firebase storage on Java Spring Boot
How to get downloadURL of uploaded file in firebase storage on Java Spring Boot

Time:12-09

In Java Spring boot, I can get the signed url using firebase-admin sdk.

Bucket bucket = StorageClient.getInstance().bucket();
Storage storage = bucket.getStorage();
BlobInfo blobInfo = BlobInfo.newBuilder(bucket.getName(), storeFileName)
                .setContentType(fileType).build();
URL url = storage.signUrl(blobInfo, 5, TimeUnit.DAYS, Storage.SignUrlOption.withV4Signature());
                String signedPath = url.toString();

But I need to get the downloadUrl instead of signed url in the Java Spring Boot like the following flutter code.

// Flutter Code
Reference ref = FirebaseStorage.instance.ref().child(storePath);
String url = (await ref.getDownloadURL()).toString();

I can't add the Firebase-Storage sdk in Java Spring, Only Mobile possible.

https://mvnrepository.com/artifact/com.google.firebase/firebase-storage/11.0.2

CodePudding user response:

The Admin SDKs for Cloud Storage are pretty thin wrappers around the GCP libraries for those platforms, which indeed don't provide a getDownloadURL method.

The closest equivalent that the GCP SDKs have is a so-called signed URL, which is similar to a download URL, but has an expiration timestamp.

If that doesn't meet your needs, you can set a metadata property on the file to generate a download URL yourself as shown in this answer: Get Download URL from file uploaded with Cloud Functions for Firebase.

  • Related