【发布时间】:2021-08-24 10:11:08
【问题描述】:
我正在尝试将媒体(图片)上传到 Firebase 存储。存储桶路径是
gs://sample-ccc80.appspot.com/SAMPLE/IMAGES
Firebase 规则:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}
我正在关注这个blog 作为教程。这是我得到的回复:
"message" : "Invalid bucket name: 'sample-ccc80.appspot.com/SAMPLE/IMAGES'"
#代码
public static String uploadFile(File file, String fileName, String bucketName) throws IOException {
BlobId blobId = BlobId.of(bucketName, fileName);
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("media").build();
String absolutePath = "/service-account.json";
Credentials credentials = GoogleCredentials.fromStream(new FileInputStream(absolutePath));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();
storage.create(blobInfo, Files.readAllBytes(file.toPath()));
String DOWNLOAD_URL = "https://firebasestorage.googleapis.com/v0/b/" + bucketName + "/o/%s?alt=media";
return String.format(DOWNLOAD_URL, URLEncoder.encode(fileName, "UTF-8"));
}
我在这里做错了什么?
【问题讨论】:
标签: java firebase spring-boot firebase-storage