Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Figure out how to do browser-based uploading, and document it well. #641

Closed
jgeewax opened this issue Jun 6, 2015 · 9 comments
Closed
Assignees
Labels
api: storage Issues related to the Cloud Storage API.

Comments

@jgeewax
Copy link
Contributor

jgeewax commented Jun 6, 2015

So there's this concept of "browser-based uploads" which basically is the following process:

  1. Client sends the server an (untrusted) policy document (basically says "I'm going to upload file which is 10mb and has metadata = {...}).
  2. Server gets this request, validates it, and if it likes it, sends back a signature (basically says "SGTM, here's my stamp of approval").
  3. 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:

  1. Can we even use gcloud-node in the client-side of a web-app?
  2. If so, we need a simple way of creating typical policy documents (as well as weird ones).
  3. 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.
  4. 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

@jgeewax jgeewax added enhancement api: storage Issues related to the Cloud Storage API. labels Jun 6, 2015
@stephenplusplus
Copy link
Contributor

I made a couple of examples here showing two different ways to handle uploads. https://github.com/stephenplusplus/gcloud-upload-example

@stellanhaglund
Copy link

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 notifications@github.com:

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
Copy link
Contributor

Which version of gcloud are you running?

@stellanhaglund
Copy link

"gcloud": "^0.21.0",

2015-09-17 15:28 GMT+02:00 Stephen Sawchuk notifications@github.com:

Which version of gcloud are you running?


Reply to this email directly or view it on GitHub
#641 (comment)
.

@stephenplusplus
Copy link
Contributor

Hmm, I haven't been able to reproduce. How large are the files you're having trouble with? I've tried with a 10MB file without issues.

I added onto the example with some options of how to download files: https://github.com/stephenplusplus/gcloud-upload-example/blob/1d6cbecb31aa2dcd98d1c8177e6c474b80b5d1f5/server.js#L89

@stellanhaglund
Copy link

about 300mb, and the files will probably be up to some gb's

2015-09-17 16:16 GMT+02:00 Stephen Sawchuk notifications@github.com:

Hmm, I haven't been able to reproduce. How large are the files you're
having trouble with? I've tried with a 10MB file without issues.

I added onto the example with some options of how to download files:
https://github.com/stephenplusplus/gcloud-upload-example/blob/1d6cbecb31aa2dcd98d1c8177e6c474b80b5d1f5/server.js#L89


Reply to this email directly or view it on GitHub
#641 (comment)
.

@stephenplusplus
Copy link
Contributor

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
Copy link
Contributor

I think we've got this one covered with file#createResumableUpload().

Related, I just stumbled upon this project over the weekend: https://github.com/makeomatic/ms-files-gce

If there's more we can do, let me know!

sofisl pushed a commit that referenced this issue Oct 11, 2022
sofisl pushed a commit that referenced this issue Oct 13, 2022
sofisl pushed a commit that referenced this issue Nov 10, 2022
sofisl pushed a commit that referenced this issue Nov 11, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@types/mocha](https://github.com/DefinitelyTyped/DefinitelyTyped) | devDependencies | major | [`^7.0.2` -> `^8.0.0`](https://renovatebot.com/diffs/npm/@types%2fmocha/7.0.2/8.0.0) |

---

### Renovate configuration

:date: **Schedule**: "after 9am and before 3pm" (UTC).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#googleapis/nodejs-dialogflow).
sofisl pushed a commit that referenced this issue Nov 17, 2022
## Code fencing
Code examples need code fencing around them to distingish from
rich text for TSDoc.

Internally b/179483748

Script used:
https://github.com/fhinkel/cloud-rad-script/blob/main/fixExampleComments.js
sofisl pushed a commit that referenced this issue Jan 10, 2023
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
Co-authored-by: Benjamin E. Coe <bencoe@google.com>
sofisl pushed a commit that referenced this issue Jan 24, 2023
* chore: updated samples/package.json [ci skip]

* chore: updated CHANGELOG.md [ci skip]

* chore: updated package.json

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
sofisl pushed a commit that referenced this issue Jan 25, 2023
* chore: updated samples/package.json [ci skip]

* chore: updated CHANGELOG.md [ci skip]

* chore: updated package.json

Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

No branches or pull requests

3 participants