GeezerVison is showing github.com — Figure out how to do browser-based uploading, and document it well. · Issue #641 · googleapis/google-cloud-node
Figure out how to do browser-based uploading, and document it well. #641DescriptionSo there's this concept of "browser-based uploads" which basically is the following process:
- Client sends the server an (untrusted) policy document (basically says "I'm going to upload
file which is 10mb and has metadata = {...}).
- Server gets this request, validates it, and if it likes it, sends back a signature (basically says "SGTM, here's my stamp of approval").
- Client is able to upload exactly that data directly to Cloud Storage, it's "credentials" for this single request being the policy document (and the signature).
So... a couple of questions:
- Can we even use gcloud-node in the client-side of a web-app?
- If so, we need a simple way of creating typical policy documents (as well as weird ones).
- Then we need a way of generating a signature (server-side) for a policy document.
Note that we're not wiring together any RPCs or anything. Just providing a method that takes a policy and spits back a signature for the user to serialize and send around however they want.
- Then we need a way of calling
upload (or similar) using the policy document and signature.
The code I'm expecting here would look like...
Server-side:
bucket.signPolicy(policy, function(signature) {
// The signature can be serialized or whatever else we want now.
});
Client-side:
var policy = bucket.policy({ /* Lots of configuration here... */ });
$.post({ /* Send the policy up to the method above */ }, function(response) {
// Create an HTML form (?) that has a field called signature = response.data ?
});
/cc @Capstan Activitystephenplusplus commented on Sep 16, 2015 stephenplusplus commented on Sep 16, 2015 stellanhaglund commented on Sep 17, 2015 Thanks alot!!
I just added that but now I'm trying to download a file using
app.get('/file/:imageId', function(req, res){
var remoteFile = bucket.file(req.params.imageId);
var localFilename = 'uploads/' + req.params.imageId;
var src = remoteFile.createReadStream()
src
.on('error', function(err) {})
.on('response', function(response) {
// Server connected and responded with the specified status and headers.
})
.on('end', function() {
// The file is fully downloaded.
})
// .pipe(fs.createWriteStream(localFilename));
res.attachment(localFilename);
src.pipe(res);
})
but for larger files I just get about 1.2 mb downloaded..
2015-09-17 1:27 GMT+02:00 Stephen Sawchuk [email protected]:
I made a couple of examples here showing two different ways to handle
uploads. https://github.com/stephenplusplus/gcloud-upload-example
—
Reply to this email directly or view it on GitHub
#641 (comment)
.
stephenplusplus commented on Sep 17, 2015 Which version of gcloud are you running? stellanhaglund commented on Sep 17, 2015
2015-09-17 15:28 GMT+02:00 Stephen Sawchuk [email protected]:
Which version of gcloud are you running?
—
Reply to this email directly or view it on GitHub
#641 (comment)
.
stephenplusplus commented on Sep 17, 2015 stellanhaglund commented on Sep 17, 2015 stephenplusplus commented on Sep 17, 2015 Would you mind opening a new issue about this? Also, please test that it still doesn't work isolated from express, e.g.:
remoteFile.createReadStream().pipe(fs.createWriteStream('./backup-file'))stephenplusplus commented on Nov 23, 2015
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|