如何为正在上载的文件指定mime类型。下面是nodejs示例https://cloud.google.com/storage/docs/object-basics#storage-upload-object-nodejs
```javascript函数uploadFile (bucketName,fileName,回调){
//实例化客户端
const storageClient = Storage();
//引用现有的桶,例如“我的-桶”
const = storageClient.bucket(bucketName);
//将本地文件上载到桶中,例如"./ local /path/ to /file.txt“
bucket.upload(fileName,(err,file) => {
if (err) { callback(err); return;}console.log(`File ${file.name} uploaded.`);callback();});
}
我总是违约
应用程序/八位流
发布于 2016-12-19 20:03:07
我自己找到了答案。您需要将此类元数据放入选项中。在任何文件里都找不到。
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();
});
}https://stackoverflow.com/questions/41229918
复制相似问题