Skip to content

minodisk/presigner

Repository files navigation

presigner Codeship Status for minodisk/presigner Go Report Card codecov GoDoc MIT License

Pre-signed URL publisher to upload files directly to Google Cloud Storage.

Usage

1. Setup bucket

[Required] Create a bucket:

gsutil mb gs://example-bucket

[Optional] Set CORS to the bucket:

To upload from browser with XHR. See Cross-Origin Resource Sharing (CORS) - Cloud Storage — Google Cloud Platform.

gsutil cors set example-cors.json gs://example-bucket

[Optional] Set default object ACL to the bucket:

To make objects accessible from any users. See defacl - Get, set, or change default ACL on buckets - Cloud Storage — Google Cloud Platform.

gsutil defacl ch -u AllUsers:R gs://example-bucket

2. Generate private key

Generate JSON private key for service account.

3. Run

presigner -account /path/to/private-key.json -bucket bucket-a -port 80

Options:

presigner -help

HTTP(S) API

Publish signed-URL

Request Body:

{
  "bucket": "example",
  "content_type": "image/jpeg",
  "md5": "XXXXXXXXXXXXXXXXXXXX"
}
  • bucket: Bucket name to upload file.
  • content_type: Content type of the file.
  • md5: [Optional] MD5 checksum of the file.

Response Body:

{
  "signed_url": "https://storage.googleapis.com/presigner/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX?Expires=1492484353&GoogleAccessId=example%40xxx.iam.gserviceaccount.com&Signature=...",
  "file_url": "https://example.storage.googleapis.com/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
}
  • signed_url: Endpoint of uploading file.
  • file_url: URL of uploaded file.
Error case
{
  "error": ""
}
  • error: Reason of error.

Upload file

PUT to signed_url, and write contents of the file to request body.

HTTP Header:

Content-Type: image/jpeg
Content-Disposition: attachement; filename="example.jpg"
  • Content-Type: Content type of the file. Same as content_type specified when publishing signed-URL.
  • Content-Disposition: [Optional] Name given when the file is downloaded.

About

Pre-signed URL publisher to upload files directly to Google Cloud Storage.

Resources

License

Stars

Watchers

Forks

Packages

No packages published