I'd like to do upload of a file to google cloud storage using javascript, I am using the google api javascript.
My bucket isn't public, I need configure the access for write but the cloud storage requires authenticate.
I tried a lot of type of configuration, but I know litte about GAE authenticate.
So, when I try to send the file, the follow message is show:
"message": "Anonymous users does not have storage.objects.create access to bucket boti-lab-dev."
Follow my code:
function start() {
// 2. Initialize the JavaScript client library.
gapi.client.init({
'apiKey': 'myApiKey',
// clientId and scope are optional if auth is not required.
'clientId': 'xxxbug.apps.googleusercontent.com',
'scope': 'https://www.googleapis.com/auth/devstorage.read_write',
}).then(function() {
// 3. Initialize and make the API request.
return gapi.client.request({
'method': 'post',
'path': 'https://www.googleapis.com/upload/storage/v1/b/myBucket/o?uploadType=media&name=nameOfFile',
'header': {
'Authorization': 'Bearer ya29.mykey'
}
})
}).then(function(response) {
console.log(response.result);
}, function(reason) {
console.log('Error: ' + reason.result.error.message);
});
};
// 1. Load the JavaScript client library.
gapi.load('client', start);
What I need create or configure? Thanks