使用 Google 云存储存储的图像的属性

Attributes for image stored using Google Cloud Storage

我正在使用 NPM documentation 将图像上传到 Google 云存储

app.post('/test', upload.single('image'), function (req, res, next) {
    });
    let bucket = gcs.bucket('bucket-name');

    bucket.upload(req.file.path, function(err, file) {
        if (err) {
            throw new Error(err);
        }
        console.log(file);
    });

    console.log(req.file);

    // req.body will hold the text fields, if there were any
})

有什么方法可以为我正在上传的文件指定自定义名称和文件类型?就我而言,它应该是一张图片。

您可以将选项传递给您的上传方法:

var options = {
  destination: 'my-image-name.jpg',
  metadata: {
    contentType: 'image/jpeg',
  }
};

bucket.upload(req.file.path, options, function(err, file) {
});