我正在尝试实现云功能,但是如果我需要这样会出错
var storage =require('@google-cloud/storage')();
Run Code Online (Sandbox Code Playgroud)
部署时是这样的
var storage = require('@google-cloud/storage');
Run Code Online (Sandbox Code Playgroud)
所以我决定使用上面的方法,但是尝试上传图片时出现错误“ TypeError:gcs.bucket不是函数”
const os = require('os');
const path = require('path');
Run Code Online (Sandbox Code Playgroud)
///
exports.onFileChange = functions.storage.object().onFinalize((event) => {
const bucket = event.bucket;
const contentType = event.contentType;
const filePath = event.name;
console.log('Changes made to bucket');
Run Code Online (Sandbox Code Playgroud)
///
if(path.basename(filePath).startsWith('renamed-')){
console.log("File was previously renamed");
return;
}
const gcs = storage({
projectId: 'clfapi'
});
Run Code Online (Sandbox Code Playgroud)
///
const destBucket = gcs.bucket(bucket);
const tmFiilePath = path.join(os.tmpdir(), path.basename(filePath));
const metadata = {contentType: contentType};
Run Code Online (Sandbox Code Playgroud)
///
return destBucket.file(filePath).download({
destination: tmFiilePath
}).then(() => {
return …
Run Code Online (Sandbox Code Playgroud)