如何解决使用 Spring Boot 将图像上传到 Firebase
大家好,我目前正在从我的 spring boot api 提交关于 firebase 存储的图像,目前一切正常,我可以提交我的图像,但图像的公共 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");
}
解决方法
如果图片是公开的,这里是网址格式
https://storage.cloud.google.com/<bucket-name>/<objectName>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。