Google Cloud Storage provides a JSON API. You can make HTTP requests within your application to the JSON API directly, which will direct the file upload and download traffic directly to Google Cloud Storage.
For downloading a file from a public Google Cloud Storage bucket, make a GET request to https://www.googleapis.com/storage/v1/b/<bucket>/o/<object>
, where <bucket>
is the name of your Google Cloud Storage bucket and <object>
is the name of a file in the bucket. This should work without any authentication, but I haven't tried it myself. You can read the docs for this API request here.
For uploading a file to a public bucket, there are multiple options. The simple approach is to make a POST request to https://www.googleapis.com/upload/storage/v1/b/<bucket>/o
, where <bucket>
is the name of your public bucket. This approach will work best for small files, less than 5 MB in size. You can read the docs for this API request here. Larger uploads will require a different approach, outlined here. Again, I haven't tried this approach myself, but it should work without authentication.
If you need to perform authenticated uploads and downloads, things get a little more complicated. Google Cloud Storage supports signed URLs for upload and download. These URLs describe specific operations on Google Cloud Storage, such as upload or download, and come with a time-sensitive signature. Anyone who has the URL can perform the specified operation on Google Cloud Storage. They're safe to pass around from server to client. You can generate the signed URL on your application's backend and pass it to the frontend. The frontend could then use the URL to upload to Google Cloud Storage directly. More info on signed URLs here.
Finally, if you need to put restrictions on the upload, such as maximum file size, you'll need to use a signed policy document, described here. This is similar to a signed URL, in that it is a URL that should be generated by your application's backend and includes a time-sensitive signature. The policy document is Base64-encoded and is included in the generated URL. It describes the restrictions on the upload. The URL signature includes the policy document, so that Google Cloud Storage knows to apply that specific policy to an upload request to that URL.
Source: My team and I are building a full-stack application hosted on Google Cloud Platform that uses Google Cloud Storage for upload and download. We're using signed policy documents for upload.