java - 如何使用 Spring Boot 将图像上传到 Firebase 上的特定参考或文件夹
问题描述
我正在尝试使用 Spring Boot 将图像上传到 Firebase 存储中的特定参考或文件夹。
我不知道如何设置图像或文件的上传目录。
下面是我直接在存储桶名称中上传文件的代码。我想将文件上传到/tests文件夹。
public String uploadFile(File file, String fileName, String contentType) throws IOException {
BlobId blobId = BlobId.of(BUCKET_NAME, fileName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType(contentType).build();
Credentials credentials = GoogleCredentials.fromStream(new FileInputStream(ResourceUtils.getFile(GOOGLE_CREDENTIALS_CONFIG_FILE)));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();
storage.create(blobInfo, Files.readAllBytes(file.toPath()));
return String.format(DOWNLOAD_URL, URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()));
}
在 react-native 方面,我设置了这样的引用,但我不知道如何在 spring-boot 中添加它。
storage().ref('tests/'+this.state.photo1.name)
.putFile(this.state.photo1.uri)
.then(response => {
console.log("Firebase response ", response);
})
.catch((e) => console.log('uploading image to firebase error => ', e));
解决方案
推荐阅读
- javascript - 使用 smtpJs 发送电子邮件时出错 (JavaScript)
- django - Django:模板中的 Crispy 表单验证错误
- javascript - 子元素包含标签时下划线模板双父p标签
- java - 我的 IntelliJ 似乎找不到我的 csv 文件?
- image - 为什么 PyCharm 笔记本中不显示降价图像?
- vb.net - 从字符串中删除文本直到“-”
- excel - 修复工作表中堆栈空间外的错误_选择更改
- javascript - JS中的基本数学问题
- python-3.x - tkinter.LabelFrame 与 Checkbutton labelwidget
- sql - 如何在表 Sql 中查找缺失的数据