【发布时间】:2017-02-01 01:11:03
【问题描述】:
我想使用 javascript 将文件上传到谷歌云存储,我正在使用 google api javascript。
我的存储桶不是公开的,我需要配置写入权限,但云存储需要身份验证。
我尝试了很多类型的配置,但我对 GAE 身份验证知之甚少。
所以,当我尝试发送文件时,显示以下消息:
“message”:“匿名用户没有 storage.objects.create 对存储桶 boti-lab-dev 的访问权限。”
按照我的代码:
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);
我需要创建或配置什么? 谢谢
【问题讨论】:
标签: google-cloud-storage google-cloud-endpoints