0
我想使用Java服務器將文件添加到我的Google Cloud Storage(實際上是Firebase存儲桶)。使用Java將文件上傳到Fire Storage for Firebase
我使用此代碼我在互聯網上得到了:
// Authenticate using a service account
Storage storage;
try {
storage = StorageOptions.newBuilder()
.setCredentials(ServiceAccountCredentials.fromStream(new FileInputStream("C:/tmp/firebasekey.json")))
.build()
.getService();
// The name for the new bucket
String bucketName = "MinhaSaude";
// Creates the new bucket
Bucket bucket = storage.create(BucketInfo.of(bucketName));
// Create blob
BlobId blobId = BlobId.of("bucket", "blob_name");
// Add metadata to the blob
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
// Upload blob to GCS (same as Firebase Storage)
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我收到後面是後桶桶= storage.create(BucketInfo.of(bucketName))誤差修改;
無論是 「無效的分區名稱: 'MinhaSaude'」 }
或minhasaude-API \ 「的剷鬥\帳戶」, 「已禁用」。
我無法找到一個滿足谷歌的bucketname。我已經使用瀏覽器將文件上傳到Firebase,並且其上傳正常。
你能鏈接到你在哪裏找到你的代碼嗎? –
我刪除了Firebase的標籤,因爲這純粹是Cloud Storage SDK代碼。 –