Skip to content

Instantly share code, notes, and snippets.

@tomconte
Last active September 25, 2015 12:38
Show Gist options
  • Select an option

  • Save tomconte/922933 to your computer and use it in GitHub Desktop.

Select an option

Save tomconte/922933 to your computer and use it in GitHub Desktop.
Uploads a directory tree to Windows Azure Blob Storage
#!/usr/bin/env python
import os
import sys
import mimetypes
from azure.storage import BlobService
BLOB_ACCOUNT = "foo"
BLOB_KEY = "bar"
DEST_CONTAINER = "test"
blobs = BlobService(BLOB_ACCOUNT, BLOB_KEY)
print blobs.create_container(DEST_CONTAINER)
mimetypes.init()
for root, dirs, files in os.walk("."):
if '.DS_Store' in files:
files.remove('.DS_Store')
for file in files:
filename = os.path.join(root, file)
type, encoding = mimetypes.guess_type(filename)
print "uploading ", filename, " type ", type
blobs.put_block_blob_from_path(DEST_CONTAINER, filename, filename, x_ms_blob_content_type=type)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment