Reputation: 1255
I'm trying to upload an image to Google Cloud Storage using the simple code locally on my machine with my service account:
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);
^
However, I get the error message below. Is the Google Cloud API only supposed to work when deployed on App Engine or am I doing something wrong here? I was able to get the Google Vision API to work locally using the same Service Account.
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)
Upvotes: 1
Views: 1129
Reputation: 6576
You need to give appropriate role to your service account. Go to the google cloud console, menu "IAM and Admin"
Upvotes: 1
Reputation: 1255
I simply had an error in the cloud console with my service account at Overdrivr pointed out
Upvotes: 0