use*_*314 2 node.js google-cloud-storage
如何为要上传的文件指定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();
});
}
Run Code Online (Sandbox Code Playgroud)
我总是默认
应用/八位字节流
自己找到答案。您需要将这种元数据放入选项中。在任何文档中都找不到。
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();
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
677 次 |
| 最近记录: |