【发布时间】:2021-04-27 14:35:49
【问题描述】:
大家好,我目前正在从我的 spring boot api 提交图像到 firebase 存储,目前一切正常我可以提交我的图像但是图像的公共 url 不可用,我想知道如何从我的 api 获取我的图像的公共 url
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");
}
【问题讨论】:
标签: firebase spring-boot google-cloud-storage firebase-storage