Reputation: 3
I am looking for help with a script to run in Python that will access a preexisting blob in Azure, and return the entire URI of a single file that will be in this blob.
I've tried a few things but they are either too old for the current libraries, or don't connect when ran.
I'm a beginner, so any help waking me through this would be much appreciated.This is what i was trying but I'm sure this is all wrong
import os, uuid
import azure.storage.blob
self.blob_type = _BlobTypes.BlockBlob
super(BlockBlobService, self).test(
account_name=Account_Name,
account_key='Account key',
sas_token=None,
is_emulated=False,
protocol='https',
endpoint_suffix='core.windows.net',
custom_domain=None,
request_session=None,
connection_string=None,
socket_timeout=None,
token_credential=None)
get_block_list(
ContainerName,
BlobName,
snapshot=None,
block_list_type=None,
lease_id=None,
timeout=None)
Upvotes: 0
Views: 1627
Reputation: 14324
From your description, suppose you want to get the blob url and the block list is uncommitted. If yes you could use make_blob_url method to implement it, this could retriever the blob url even the blob doesn't exist.
Below is my test code, firstly I create block_list but uncommitted, this could get the blob url, however even you could get the blob url, this url is not accessible cause the blob doesn't exist.
I use the azure-storage-blob==2.1.0
.
from azure.storage.blob import BlockBlobService, PublicAccess,ContentSettings,BlockListType,BlobBlock
connect_str ='connection string'
block_blob_service = BlockBlobService(connection_string=connect_str)
containername='test'
blobname='abc-test.txt'
block_blob_service.put_block(container_name=containername,blob_name=blobname,block=b'AAA',block_id=1)
block_blob_service.put_block(container_name=containername,blob_name=blobname,block=b'BBB',block_id=2)
block_blob_service.put_block(container_name=containername,blob_name=blobname,block=b'CCC',block_id=3)
block_list=block_blob_service.get_block_list(container_name=containername,blob_name=blobname,block_list_type=BlockListType.All)
uncommitted = len(block_list.uncommitted_blocks)
print(uncommitted)
exists=block_blob_service.exists(container_name=containername,blob_name=blobname)
print(exists)
blob_url=block_blob_service.make_blob_url(container_name=containername,blob_name=blobname)
print(blob_url)
block_list = [BlobBlock(id='1'), BlobBlock(id='2'), BlobBlock(id='3')]
block_blob_service.put_block_list(container_name=containername,blob_name=blobname,block_list=block_list)
exists=block_blob_service.exists(container_name=containername,blob_name=blobname)
print(exists)
blob_url=block_blob_service.make_blob_url(container_name=containername,blob_name=blobname)
print(blob_url)
Hope this is what you want, if you still have other problem please feel free to let me know.
Upvotes: 1