Friday, March 14, 2014

Uploading to Google Cloud Storage with curl

Sometimes you want to upload a file to Google Cloud Storage. You don't want to use the UI, you don't want to use gsutil, and you don't want to write a program using one of the libraries. You just want to upload it. Manually. With curl.

Authorization is outside the scope of this article. You'll need a way to get an access token with OAuth 2, or you'll need a bucket that allows anonymous object writes.

Here's the command for a basic upload:

$> curl -d 'Contents of the file' 'https://www.googleapis.com/upload/storage/v1beta2/b/mybucket/o?name=name_of_file.txt&uploadType=media'

Bam, easy. But maybe you want to write an actual file and not just some ad-hoc text:

$> curl -X POST -T filename 'https://www.googleapis.com/upload/storage/v1/b/mybucket/o?name=name_of_file.txt&uploadType=media'

This doesn't tell Google Cloud Storage what kind of thing we're uploading, though. We need to set a Content-Type header for that.

$> curl -H "Content-Type: image/jpeg" --data-binary @picture.jpg 'https://www.googleapis.com/upload/storage/v1beta2/b/mybucket/o?name=name_of_file.txt&uploadType=media'

1 comment:

  1. Casinos Near Me - CBSDetroit.com
    The most common casinos 구미 출장마사지 near me include: Borgata 경기도 출장안마 Hotel 문경 출장마사지 Casino 서울특별 출장샵 & Spa 상주 출장마사지 & The Water Club, The Water Club, Borgata Hotel Casino & Spa, and Atlantic City Convention

    ReplyDelete