def save_file(binary, filename, public=True, mime_type="application/octet-stream"): today = datetime.now().strftime("%Y/%m/%d/") filename = today + filename from urlparse import urljoin from settings import BAE_BCS, BCS_HOST, BUCKET_NAME, BSC_FOLDER object_name = "%s%s" % (BSC_FOLDER, filename) err, resp = BAE_BCS.put_object(BUCKET_NAME, object_name, binary) if err != 0: raise Exception(resp) if public: #err, resp = BAE_BCS.make_public(BUCKET_NAME, object_name) acl_read = '{"statements":[{"action":["get_object"],"effect":"allow","resource":["%s%s"],"user":["*"]}]}' % ( BUCKET_NAME, object_name) err, resp = BAE_BCS.set_acl(BUCKET_NAME, object_name, acl_read) if err != 0: BAE_BCS.del_object(BUCKET_NAME, object_name) raise Exception(resp) url = urljoin(BCS_HOST, BUCKET_NAME) + object_name return url, url
def delete_file(file_path): from urlparse import urlsplit from settings import BAE_BCS path = urlsplit(file_path).path _, bucket_name, object_name = path.split("/", 2) object_name = "/" + object_name err, resp = BAE_BCS.del_object(bucket_name, object_name) if err != 0: raise Exception(resp)
def delete_file(file_path): from urlparse import urlsplit from settings import BAE_BCS path = urlsplit(file_path).path _, bucket_name, object_name = path.split("/", 2) object_name = "/" + object_name bucket = BAE_BCS.bucket(bucket_name) bcs_obj = bucket.object(object_name) bcs_obj.delete()