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(); }); }
- 谷歌云存储对象删除谷歌API,Node.js和request.del()
- 如何在Node.js中使用bigquery API获取800万条Google Cloudlogging?
- 在通过file.createWriteStream()传输到GCP时,获取ESOCKETTIMEOUT,ECONNRESET或套接字会挂载大文件。
- Node.jsstream直接上传到Google云端存储
- Google Cloud Storage签署url – NodeJS
- Google云端存储忽略分隔符
- 同样的Google云端存储上传脚本可以在一台电脑上运行,但是不能运行,为什么?
- 通过快递中间件,从谷歌云存储中提供静态文件
- 通过GAE托pipe的node.js express服务器上传大文件