如何为我上传的文件指定mime类型。我正在关注此nodejs示例https://cloud.google.com/storage/docs/object-basics#storage-upload-object-nodejs
```
function uploadFile (bucketName, fileName, callback) {
// Instantiates a client
const storageClient = Storage();
// References an existing bucket, e.g. "my-bucket"
const bucket = storageClient.bucket(bucketName);
// Uploads a local file to the bucket, e.g. "./local/path/to/file.txt"
bucket.upload(fileName, (err, file) => {
if (err) {
callback(err);
return;
}
console.log(`File ${file.name} uploaded.`);
callback();
});
}
我总是默认
应用/八位字节流
答案 0 :(得分:4)
自己找到答案。您需要将此类元数据放入选项中。无法在任何文档中找到它。
function uploadFile (bucketName, fileName, callback) {
// Instantiates a client
const storageClient = Storage();
// References an existing bucket, e.g. "my-bucket"
const bucket = storageClient.bucket(bucketName);
// STARTING FROM HERE
const options = {
metadata: {
contentType: 'image/jpeg',
},
}
// TO HERE
// Uploads a local file to the bucket, e.g. "./local/path/to/file.txt"
bucket.upload(fileName, options, (err, file) => {
if (err) {
callback(err);
return;
}
console.log(`File ${file.name} uploaded.`);
callback();
});
}