Upload multiple files from folder to Azure Blob storage using Azure Storage SDK for Python











up vote
1
down vote

favorite












I have some images in a local folder on my windows machine. I want to upload all images to the same blob in the same container.



I know how to upload a single file with Azure Storage SDKs BlockBlobService.create_blob_from_path(), but I do not see a possibility to upload all images in the folder at once.



However, the Azure Storage Explorer provides a functionality for this, so it must be possible somehow.



Is there a function providing this service or do I have to loop over all files in a folder and run create_blob_from_path() multiple times for the same blob?










share|improve this question


















  • 2




    you have to loop :-) what do you mean to the same blob ? you will upload all images to the same container ?
    – Thomas
    Nov 10 at 1:05

















up vote
1
down vote

favorite












I have some images in a local folder on my windows machine. I want to upload all images to the same blob in the same container.



I know how to upload a single file with Azure Storage SDKs BlockBlobService.create_blob_from_path(), but I do not see a possibility to upload all images in the folder at once.



However, the Azure Storage Explorer provides a functionality for this, so it must be possible somehow.



Is there a function providing this service or do I have to loop over all files in a folder and run create_blob_from_path() multiple times for the same blob?










share|improve this question


















  • 2




    you have to loop :-) what do you mean to the same blob ? you will upload all images to the same container ?
    – Thomas
    Nov 10 at 1:05















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I have some images in a local folder on my windows machine. I want to upload all images to the same blob in the same container.



I know how to upload a single file with Azure Storage SDKs BlockBlobService.create_blob_from_path(), but I do not see a possibility to upload all images in the folder at once.



However, the Azure Storage Explorer provides a functionality for this, so it must be possible somehow.



Is there a function providing this service or do I have to loop over all files in a folder and run create_blob_from_path() multiple times for the same blob?










share|improve this question













I have some images in a local folder on my windows machine. I want to upload all images to the same blob in the same container.



I know how to upload a single file with Azure Storage SDKs BlockBlobService.create_blob_from_path(), but I do not see a possibility to upload all images in the folder at once.



However, the Azure Storage Explorer provides a functionality for this, so it must be possible somehow.



Is there a function providing this service or do I have to loop over all files in a folder and run create_blob_from_path() multiple times for the same blob?







python azure azure-storage azure-blob-storage






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 14:31









gehbiszumeis

849218




849218








  • 2




    you have to loop :-) what do you mean to the same blob ? you will upload all images to the same container ?
    – Thomas
    Nov 10 at 1:05
















  • 2




    you have to loop :-) what do you mean to the same blob ? you will upload all images to the same container ?
    – Thomas
    Nov 10 at 1:05










2




2




you have to loop :-) what do you mean to the same blob ? you will upload all images to the same container ?
– Thomas
Nov 10 at 1:05






you have to loop :-) what do you mean to the same blob ? you will upload all images to the same container ?
– Thomas
Nov 10 at 1:05














1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










There is no direct way to do this. You can go through the azure storage python SDK blockblobservice.py and baseblobservice.py for details.



As you mentioned, you should loop over it. The sample code as below:



from azure.storage.blob import BlockBlobService, PublicAccess
import os

def run_sample():
block_blob_service = BlockBlobService(account_name='your_account', account_key='your_key')
container_name ='t1s'

local_path = "D:\Test\test"

for files in os.listdir(local_path):
block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))


# Main method.
if __name__ == '__main__':
run_sample()


The files in local:
enter image description here



After code execution, they are uploaded to azure:
enter image description here






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227677%2fupload-multiple-files-from-folder-to-azure-blob-storage-using-azure-storage-sdk%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    There is no direct way to do this. You can go through the azure storage python SDK blockblobservice.py and baseblobservice.py for details.



    As you mentioned, you should loop over it. The sample code as below:



    from azure.storage.blob import BlockBlobService, PublicAccess
    import os

    def run_sample():
    block_blob_service = BlockBlobService(account_name='your_account', account_key='your_key')
    container_name ='t1s'

    local_path = "D:\Test\test"

    for files in os.listdir(local_path):
    block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))


    # Main method.
    if __name__ == '__main__':
    run_sample()


    The files in local:
    enter image description here



    After code execution, they are uploaded to azure:
    enter image description here






    share|improve this answer



























      up vote
      2
      down vote



      accepted










      There is no direct way to do this. You can go through the azure storage python SDK blockblobservice.py and baseblobservice.py for details.



      As you mentioned, you should loop over it. The sample code as below:



      from azure.storage.blob import BlockBlobService, PublicAccess
      import os

      def run_sample():
      block_blob_service = BlockBlobService(account_name='your_account', account_key='your_key')
      container_name ='t1s'

      local_path = "D:\Test\test"

      for files in os.listdir(local_path):
      block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))


      # Main method.
      if __name__ == '__main__':
      run_sample()


      The files in local:
      enter image description here



      After code execution, they are uploaded to azure:
      enter image description here






      share|improve this answer

























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        There is no direct way to do this. You can go through the azure storage python SDK blockblobservice.py and baseblobservice.py for details.



        As you mentioned, you should loop over it. The sample code as below:



        from azure.storage.blob import BlockBlobService, PublicAccess
        import os

        def run_sample():
        block_blob_service = BlockBlobService(account_name='your_account', account_key='your_key')
        container_name ='t1s'

        local_path = "D:\Test\test"

        for files in os.listdir(local_path):
        block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))


        # Main method.
        if __name__ == '__main__':
        run_sample()


        The files in local:
        enter image description here



        After code execution, they are uploaded to azure:
        enter image description here






        share|improve this answer














        There is no direct way to do this. You can go through the azure storage python SDK blockblobservice.py and baseblobservice.py for details.



        As you mentioned, you should loop over it. The sample code as below:



        from azure.storage.blob import BlockBlobService, PublicAccess
        import os

        def run_sample():
        block_blob_service = BlockBlobService(account_name='your_account', account_key='your_key')
        container_name ='t1s'

        local_path = "D:\Test\test"

        for files in os.listdir(local_path):
        block_blob_service.create_blob_from_path(container_name,files,os.path.join(local_path,files))


        # Main method.
        if __name__ == '__main__':
        run_sample()


        The files in local:
        enter image description here



        After code execution, they are uploaded to azure:
        enter image description here







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 12 at 5:58

























        answered Nov 12 at 5:53









        Ivan Yang

        1,792115




        1,792115






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227677%2fupload-multiple-files-from-folder-to-azure-blob-storage-using-azure-storage-sdk%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python