chelo_c chelo_c - 25 days ago 6x
Javascript Question

Google Cloud Storage Javascript Usage

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

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

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

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

The problem is:

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.

How can I achieve this?



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":"" },
["eq", "$Content-Type", "image/jpeg" ],
["content-length-range", 0, 1000000]
var policyJson64 = new Buffer(''+policyJson).toString('base64');
var sign = crypto.createSign('RSA-SHA256');
var sig = sign.sign(pemKey, 'base64')

And my post form is the following:

<form action="" 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="">
<input type="hidden" name="acl" value="bucket-owner-read">
<input type="hidden" name="success_action_redirect" value="">
<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">

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.

I get this error:

The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.

What should I put?


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


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.

Clone the sample:

git clone


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