Create a bucket
- Open a terminal window.
- Use the
gsutil mb
command and a unique name to create a bucket:This quickstart uses a bucket named "my-awesome-bucket." You will need to choose your own, unique, bucket name. gsutil mb gs://my-awesome-bucket/
If successful, the command returns:You've just created a bucket where you can store your stuff! Creating gs://my-awesome-bucket/...
Upload an object into your bucket
- Right-click on the following icon: . Save it somewhere on your computer, such as on the desktop.
- Use the
gsutil cp
command to copy the icon from the location where you saved it to the bucket you created:If successful, the command returns: gsutil cp Desktop/cloud-storage-logo.png gs://my-awesome-bucket
You've just stored an object in your bucket. Copying file://Desktop/cloud-storage-logo.png [Content-Type=image/png]... Uploading gs://my-awesome-bucket/cloud-storage-logo.png: 0 B/2.58 KiB Uploading gs://my-awesome-bucket/cloud-storage-logo.png: 2.58 KiB/2.58 KiB
Download an object from your bucket
- Use the
gsutil cp
command to download the icon you stored in your bucket to somewhere on your computer, such as the desktop:If successful, the command returns: gsutil cp gs://my-awesome-bucket/cloud-storage-logo.png Desktop
You've just downloaded something from your bucket. Copying gs://my-awesome-bucket/cloud-storage-logo.png... Downloading file://Desktop/cloud-storage-logo.png: 0 B/2.58 KiB Downloading file://Desktop/cloud-storage-logo.png: 2.58 KiB/2.58 KiB
Copy an object to a folder in the bucket
- Use the
gsutil cp
command to create a folder and copy the icon into it:gsutil cp gs://my-awesome-bucket/cloud-storage-logo.png gs://my-awesome-bucket/just-a-folder/
If successful, the command returns:You've just copied your object into a new folder in your bucket. Copying gs://my-awesome-bucket/cloud-storage-logo.png [Content-Type=image/png]... Copying ...my-awesome-bucket/just-a-folder/cloud-storage.logo.png: 2.58 KiB/2.58 KiB
List contents of a bucket or folder
- Use the
gsutil ls
command to list the contents of the bucket:If successful, the command returns a message similar to: gsutil ls gs://my-awesome-bucket
You've just seen the contents of your bucket. gs://my-awesome-bucket/cloud-storage-logo.png gs://my-awesome-bucket/just-a-folder/
List details for an object
- Use the
gsutil ls
command, with the-l
flag to get some details about an object:If successful, the command returns a message similar to: gsutil ls -l gs://my-awesome-bucket/cloud-storage-logo.png
You've just obtained information about the object's size and date of creation. 2638 2016-02-26T23:05:14Z gs://my-awesome-bucket/cloud-storage-logo.png TOTAL: 1 objects, 2638 bytes (2.58 KiB)
Make your object publicly accessible
- Use the
gsutil acl ch
command to grant all users read permission for the object stored in your bucket:If successful, the command returns: gsutil acl ch -u AllUsers:R gs://my-awesome-bucket/cloud-storage-logo.png
Now anyone can get your object. Updated ACL on gs://my-awesome-bucket/cloud-storage-logo.png
- To remove this permission, use the command:
If successful, the command returns: gsutil acl ch -d AllUsers gs://my-awesome-bucket/cloud-storage-logo.png
You have removed public access to this object. Updated ACL on gs://my-awesome-bucket/cloud-storage-logo.png
Give someone access to your bucket
- Use the
gsutil acl ch
command to give a specific email address read and write permission for your bucket:If successful, the command returns: gsutil acl ch -u user@gmail.com:W gs://my-awesome-bucket
Now someone else can put things into and take things out of your bucket. Updated ACL on gs://my-awesome-bucket/
- To remove this permission, use the command:
If successful, the command returns: gsutil acl ch -d user@gmail.com gs://my-awesome-bucket
You have removed the user's access to this bucket. Updated ACL on gs://my-awesome-bucket/
Delete objects
- Use the
gsutil rm
command to delete an object:If successful, the command returns: gsutil rm gs://my-awesome-bucket/cloud-storage-logo.png
This copy of the object is no longer stored on Cloud Storage (though the copy you made in the folder Removing gs://my-awesome-bucket/cloud-storage-logo.png...
just-a-folder/
still exists).
Clean up
To avoid incurring charges to your Google Cloud Platform account for the resources used in this quickstart:
- Open a terminal window (if not already open).
- Use the gsutil
rm command
with the-r
flag to delete the bucket and anything inside of it:If successful, the command returns a message similar to: gsutil rm -r gs://my-awesome-bucket
Your bucket and its contents are deleted. Removing gs://my-awesome-bucket/just-a-folder/cloud-storage.logo.png#1456530077282000... Removing gs://my-awesome-bucket/...
No comments:
Post a Comment