Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions gcloud/storage/bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def copy_blob(blob, destination_bucket, new_name=None,
new_blob._set_properties(copy_result)
return new_blob

def upload_file(self, filename, blob_name=None, connection=None):
def upload_file(self, filename, blob_name=None, connection=None, content_type=None):
"""Shortcut method to upload a file into this bucket.

Use this method to quickly put a local file in Cloud Storage.
Expand All @@ -480,6 +480,15 @@ def upload_file(self, filename, blob_name=None, connection=None):
>>> print bucket.list_blobs()
[<Blob: my-bucket, my-file.txt>]

The content type of the file can also be specified

>>> from gcloud import storage
>>> connection = storage.get_connection()
>>> bucket = storage.get_bucket('my-bucket', connection=connection)
>>> bucket.upload_file('~/my-file.txt', 'remove-text-file.txt', content_type='application/octet-stream')
>>> print bucket.list_blobs()
[<Blob: my-bucket, remote-text-file.txt']

:type filename: string
:param filename: Local path to the file you want to upload.

Expand All @@ -500,7 +509,7 @@ def upload_file(self, filename, blob_name=None, connection=None):
if blob_name is None:
blob_name = os.path.basename(filename)
blob = Blob(bucket=self, name=blob_name)
blob.upload_from_filename(filename, connection=connection)
blob.upload_from_filename(filename, connection=connection, content_type=content_type)
return blob

def upload_file_object(self, file_obj, blob_name=None, connection=None):
Expand Down