Last active
August 29, 2015 14:15
-
-
Save dhermes/ed61e3a5e8206b7be471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> # Download https://www.gstatic.com/webp/gallery/4.sm.webp as file.webp | |
>>> | |
>>> import mimetypes | |
>>> | |
>>> from gcloud import storage | |
>>> from gcloud.storage import _implicit_environ | |
>>> from gcloud.storage.blob import Blob | |
>>> | |
>>> storage.set_defaults() | |
>>> CONNECTION = _implicit_environ.CONNECTION | |
>>> | |
>>> bucket_name = '....FILL IN HERE....' | |
>>> bucket = storage.Bucket(name=bucket_name, connection=CONNECTION) | |
>>> if bucket.exists(): | |
... print 'Bucket exists' | |
... else: | |
... print 'Creating bucket' | |
... bucket = CONNECTION.create_bucket(bucket_name) | |
... | |
Creating bucket | |
>>> filename = 'file.webp' | |
>>> blob = Blob(bucket=bucket, name=filename, | |
... properties={'contentType': 'image/webp'}) | |
>>> | |
>>> guessed_type, guessed_encoding = mimetypes.guess_type(filename) | |
>>> print 'guessed_type:', guessed_type | |
guessed_type: None | |
>>> print 'guessed_encoding:', guessed_encoding | |
guessed_encoding: None | |
>>> with open(filename, 'rb') as file_obj: | |
... blob.upload_from_file(file_obj, content_type=blob.content_type) | |
... | |
>>> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment