【发布时间】:2021-12-07 01:29:31
【问题描述】:
我可以使用 Firebase Admin SDK 在 Google Cloud Storage 上上传文件。但是,我无法为文件设置正确的 contentType,并且上传的文件默认为 application/octet-stream。我无法使用 Java Admin SDK 设置正确的内容类型/元数据的任何文档。如何更改默认 contentType?
这是我如何上传文件的代码 sn-p。
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_HH:mm:ss");
String timestamp = dateFormat.format(date);
StorageClient storageClient = StorageClient.getInstance();
Bucket storageBucket = storageClient.bucket();
// Not sure if I'm doing this correctly
BlobInfo blobInfo = BlobInfo.newBuilder(storageBucket.getName(), "filename")
.setContentType("vnd.ms-excel").build();
// File upload task
storageClient.bucket().create(backupFolderPath + fileNamePrefix + "_" + timestamp + ".csv", file);
【问题讨论】:
标签: java google-cloud-storage firebase-storage