Created
January 9, 2017 05:16
-
-
Save tonybaloney/e7159fbe72b81decce0395ceb87aa358 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
from pprint import pprint | |
from libcloud.storage.types import Provider | |
from libcloud.storage.providers import get_driver | |
import os | |
os.environ.get('http_proxy', 'http://localhost:8888/') | |
import libcloud.security | |
libcloud.security.VERIFY_SSL_CERT = False | |
libcloud.security.CA_CERTS_PATH = '/Users/anthonyshaw/charles.pem' | |
GoogleStorageDriver = get_driver(Provider.GOOGLE_STORAGE) | |
driver = GoogleStorageDriver(key='GOOG***', secret='****') | |
containers = driver.list_containers() | |
container_objects = driver.list_container_objects(containers[0]) | |
pprint(containers) | |
pprint(container_objects) | |
driver.download_object(container_objects[0], '/tmp/test.jpg', overwrite_existing=True) | |
with open('/tmp/test_stream.jpg', 'wb') as test_stream: | |
driver.download_object_as_stream(container_objects[0], test_stream) | |
FILE_PATH = '/Users/anthonyshaw/my_image.jpg' | |
# This method blocks until all the parts have been uploaded. | |
extra = {'content_type': 'application/octet-stream'} | |
obj = driver.upload_object(file_path=FILE_PATH, | |
container=containers[0], | |
object_name='me.jpg', | |
extra=extra) | |
with open(FILE_PATH, 'rb') as iterator: | |
obj = driver.upload_object_via_stream(iterator=iterator, | |
container=containers[0], | |
object_name='me.jpg', | |
extra=extra) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I didn't know download_object_as_stream could take test_stream as second arg? It looks like the second argument is chunk_size. I'm confused.