Pre-signed URL publisher to upload files directly to Google Cloud Storage.
gsutil mb gs://example-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
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
Generate JSON private key for service account.
presigner -account /path/to/private-key.json -bucket bucket-a -port 80
presigner -help
{
"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.
{
"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": ""
}
error
: Reason of error.
PUT
to signed_url
, and write contents of the file to request body.
Content-Type: image/jpeg
Content-Disposition: attachement; filename="example.jpg"
Content-Type
: Content type of the file. Same ascontent_type
specified when publishing signed-URL.Content-Disposition
: [Optional] Name given when the file is downloaded.