Google云端存储Javascript用法 [英] Google Cloud Storage Javascript Usage

查看:283
本文介绍了Google云端存储Javascript用法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用 JSON API 将图片上传到Google云端存储上的存储桶中>,使用Javascript示例:
Api Javascript示例

i am trying to upload images into buckets on Google Cloud Storage using the JSON API, using the Javascript sample: Api Javascript Sample

我可以上传图片,但它要求我登录我的google帐户。

I am able to upload pictures but it asks me to log in on my google account.

示例中有一个授权按钮,我了解它管理的OAuth凭据。

Tthe sample has an Authorization button, which I understand manages the OAuth credentials.

    function checkAuth() {
  gapi.auth.authorize({
    client_id: clientId,
    scope: scopes,
    immediate: true
  }, handleAuthResult);
}

问题是:

我想要验证,而不需要弹出屏幕,这意味着无需使用Google登录。因为我的客户不知道电子邮件或密码,所以我想要自动。

I want to authenticate without having the pop up screen, that means without login in with Google. Because my client doesn't know the email or password, I want it to be automatically.

如何实现?

谢谢!

---------------------------- -UPDATE --------------------

-----------------------------UPDATE--------------------

因此,接下来Brandon的回答我做了以下:

So following Brandon's answer i have done the following:

我已经创建了我的策略文档,并且这样签名:

I have created my policy document and signed it like this:

var http = require('http');
var fs = require('fs');
var crypto = require('crypto');
var express = require('express');
var app = express();
var p12ToPem = require("./node_modules/p12-to-pem/p12ToPem.js");
var p12File = fs.readFileSync("./KEY.p12");
var pemKey = p12ToPem(p12File, "notasecret");
 var policyJson={"expiration": "2050-06-16T11:11:11Z",
"conditions": [["starts-with", "$key", "" ],
{"acl": "bucket-owner-read" },
{"bucket": "my-bucket'name"},
{"success_action_redirect":"http://www.example.com/success_notification.html" },
 ["eq", "$Content-Type", "image/jpeg" ],
 ["content-length-range", 0, 1000000]
 ]
};
var policyJson64 = new Buffer(''+policyJson).toString('base64');
var sign = crypto.createSign('RSA-SHA256');
sign.update(policyJson64);
var sig = sign.sign(pemKey, 'base64')
console.log("policyJson64:"+policyJson64);
console.log("sig:"+sig);

我的帖子形式如下:

  <form action="http://my-bucket-name.storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="">
<input type="hidden" name="bucket" value="my-bucket-name">
<input type="hidden" name="Content-Type" value="image/jpeg">
<input type="hidden" name="GoogleAccessId" value="884257827820-so77htet9tafrcjjp83m7api9lh12qsn@developer.gserviceaccount.com">
<input type="hidden" name="acl" value="bucket-owner-read">
<input type="hidden" name="success_action_redirect" value="http://www.example.com/success_notification.html">
<input type="hidden" name="policy" value="DONT KNOW WHAT TO PUT HERE">
<input type="hidden" name="signature" value="NEITHER HERE">
<input name="file" type="file">
<input type="submit" value="Upload">

javascrypt我似乎无法找出什么进入政策和什么到签名,是!我已经阅读API,但不清楚在这些2个输入的内容。
我试图把策略输入PolicyJson64和sig的值。我已经尝试把签名输入sig和pemKey的值。

No matter the combinations obtained in the javascrypt I cant seem to figure out what goes into policy and what into signature,and YES! I have read the API but it is not clear on what goes in those 2 inputs.. I have tried putting on the policy input the value of PolicyJson64 and sig as well. And I have tried putting on the signature input the value of sig and pemKey too.

我得到这个错误:

<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
</Message>
<StringToSign>
a/vDHoeJ1jIZibjgLnS/ZfMftmyz8IaISJiVt1b2wDNbDjnSR+0HyEDW9/Lew7ufMjU9xdtX/Uld06IJbeYz3OWGHnH4osJNS614RoDVd7lq2qft+bSCqYPtkagJiUWs9SNOPvuQzISthqloPQOwJ1LLXHYmV52c73OpexAnSR4=
</StringToSign>
</Error>

我应该放什么?

----- UPDATE ------

------UPDATE------

请不要复制粘贴不起作用的文档。
Bounty添加

Please do not copy paste documentation that is not helping. Bounty Added

推荐答案

由于Google云端存储没有上传图片的简单方法(2014)使用Amazon Web Services甚至带有一个NodeJS示例代码。使用方便简单。

As Google Cloud Storage doesnt have a simple way to upload an image (2014), I ended up using Amazon Web Services which even comes with a NodeJS Sample Code. Easy and simple to use.

http://aws.amazon.com/es/developers/getting-started/nodejs/

复制示例:

git clone https://github.com/awslabs/aws-nodejs-sample.git

安装:

npm install

执行:

node sample.js

示例带有存储桶使用,甚至将文件存储在存储桶中。所以这将使它。请务必更改您的凭据:

The Sample comes with bucket usage and they even store a file in the bucket. So that will make it. Make sure to change your credentials:

aws_access_key_id = YOUR_ACCESS_KEY_ID
aws_secret_access_key = YOUR_SECRET_ACCESS_KEY

干杯!

这篇关于Google云端存储Javascript用法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆