Google Storage nodejs上传MIME TYPE

如何为我正在上传的文件指定MIMEtypes。 我正在关注这个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, eg "my-bucket" const bucket = storageClient.bucket(bucketName); // Uploads a local file to the bucket, eg "./local/path/to/file.txt" bucket.upload(fileName, (err, file) => { if (err) { callback(err); return; } console.log(`File ${file.name} uploaded.`); callback(); }); } 

我总是得到默认

应用/八位字节stream

自己find答案。 您需要将这种types的元数据放入选项中。 在任何文档中找不到它。

 function uploadFile (bucketName, fileName, callback) { // Instantiates a client const storageClient = Storage(); // References an existing bucket, eg "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, eg "./local/path/to/file.txt" bucket.upload(fileName, options, (err, file) => { if (err) { callback(err); return; } console.log(`File ${file.name} uploaded.`); callback(); }); }