0

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)
2
  • Please edit your question and include the code you’ve written and the issues you’re running into with that code. Commented Apr 22, 2020 at 1:36
  • @GauravMantri done. Sorry about that. Commented Apr 22, 2020 at 1:51

1 Answer 1

1

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)

enter image description here

Hope this is what you want, if you still have other problem please feel free to let me know.

Sign up to request clarification or add additional context in comments.

4 Comments

If you could share the top of your code for the libraries I would need, and how to initialize that'd be awesome. Just redact or replace your acct specific info. Also, I know the name of the Blob i want the info from.
@Cecil Ware,I Update the code, use the azure-storage-blob==2.1.0 should be same like yours both are v2 sdk.
@Cecil Ware, any update? If this could help you, you could accept it as the answer.meta.stackexchange.com/a/5235
Thanks @George Chen, Worked perfectly!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.