我尝试使用我的服务帐户在我的计算机上使用本地简单代码将图像上传到Google云端存储:
const storage = require('@google-cloud/storage');
const fs = require('fs');
const gcs = storage({
projectId: 'ID',
keyFilename: 'KEYNAME'
});
var bucket = gcs.bucket('BUCKET NAME');
bucket.upload('hiking-image.jpg', function(err, file) {
if (err) throw new Error(err);
});
if (err) throw new Error(err);
^
但是,我收到以下错误消息。谷歌云API是否应该在部署在App Engine上时工作,或者我在这里做错了什么?我能够使用相同的服务帐户让Google Vision API在本地工作。
Error: ApiError: Forbidden
at /Users/user/google-cloud/upload/upload.js:10:20
at Pumpify.<anonymous> (/Users/user/node_modules/@google-cloud/storage/src/bucket.js:1218:9)
at emitOne (events.js:101:20)
at Pumpify.emit (events.js:188:7)
at Pumpify.Duplexify._destroy (/Users/user/node_modules/duplexify/index.js:184:15)
at /Users/user/node_modules/duplexify/index.js:175:10
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)