[英]Uploading images to Firebase with Spring boot
Hello everyone I'm currently working on the submission of images on firebase storage from my spring boot api, currently everything works I can submit my images but the public url of the image is not available, I would like to know how to get a public url of my image from my api Hello everyone I'm currently working on the submission of images on firebase storage from my spring boot api, currently everything works I can submit my images but the public url of the image is not available, I would like to know how to get a public url 我的图像来自我的 api
public void uploadFile(MultipartFile multipartFile, String path) throws IOException {
String objectName = generateFileName(multipartFile);
StorageOptions storageOptions = StorageOptions.newBuilder()
.setProjectId("my-project")
.setCredentials(GoogleCredentials
.fromStream(new ClassPathResource("firebase_admin.json").getInputStream()))
.build();
Storage storage = storageOptions.getService();
BlobId blobId = BlobId.of("bucket-name", objectName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType(multipartFile.getContentType()).build();
Blob blob = storage.create(blobInfo, multipartFile.getBytes());
System.out.println("UPLOAD FILE" + multipartFile.getName() + " " + multipartFile.getSize() + " octet");
}
If the image is public, here the URL pattern如果图像是公开的,这里是 URL 模式
https://storage.cloud.google.com/<bucket-name>/<objectName>
Use the alt parameter in the url to get the download URL like this:使用 url 中的 alt 参数来下载 URL,如下所示:
https://firebasestorage.googleapis.com/v0/b/<bucket-name>/o/<objet-name>?alt=media
Get more detail in this post: https://medium.com/teamarimac/file-upload-and-download-with-spring-boot-firebase-af068bc62614在这篇文章中获取更多详细信息: https://medium.com/teamarimac/file-upload-and-download-with-spring-boot-firebase-af068bc62614
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.