0
votes

I'm building a web app that needs to let users upload large files. I would like to use Google Cloud Storage. I've spent several days reading the docs, and I'm still not sure how to actually initiate the upload from the browser.

I understand that a signed URL is needed for this purpose (allowing an anonymous user to upload to a bucket), which I can generate on the server and send to the browser.

However, the JavaScript Client Library seems intended to only run on an application server with authentication as a User or Service Account. For example, the @google-cloud/storage package has a method for generating signed URLs, but not for uploading a file using that signed URL.

What am I missing?

PS - These will be big files, so it would be nice to perform resumeable uploads.

UPDATE: From what I can tell (hints here), you just need to PUT or POST to the signed URL. So I guess I should go snag a generic file upload utility that wraps XHR. (Maybe jQuery?)

1

1 Answers

1
votes

I don't believe such a library exists. You'll probably want to just use standard JavaScript or your favorite library for making remove HTTP calls.

You'll make an initial POST to the signed URL. This will result in a 201, like so:

HTTP/1.1 201 Created
Location: https://example.storage.googleapis.com/music.mp3?upload_id=tvA0ExBntDa...gAAEnB2Uowrot
Date: Fri, 01 Oct 2010 21:56:18 GMT
Content-Length: 0
Content-Type: audio/mpeg

The URL in the "Location" header, including the upload_id parameter, is the URL to which you'll follow up with a PUT with your data. That operation can be interrupted and resumed.

There's more documentation on exactly how to use resumable uploads with XML here: https://cloud.google.com/storage/docs/xml-api/resumable-upload