locked
Datastore.download only accepts parent directory as prefix RRS feed

  • Question

  • from azureml.core.datastore import Datastore
    
    my_ds = Datastore.get(ws, "jad")
    
    # Line below downloads the whole parent directory
    
    my_ds.download(target_path="./output", prefix="parent_dir", overwrite=False) 
    
    # Line below doesn't download anything
    
    my_ds.download(target_path="./output", prefix="parent_dir/dir1", overwrite=False) 


    • Edited by jadhosn Friday, December 6, 2019 10:08 PM
    Friday, December 6, 2019 10:05 PM

All replies

  • Hi,

    To specify “parent_dir/dir1” as prefix when downloading your data, the folder “dir1” should already exist in your blob container. Ensure that you have created the folder “dir1” and uploaded your data into the folder (sample shown below). Hope this helps. Thanks.

    import azureml.core
    import azureml.data
    from azureml.core import Workspace, Datastore
    from azureml.data.azure_storage_datastore import AzureFileDatastore, AzureBlobDatastore
    
    ws = Workspace.from_config()
    
    datastore = Datastore.register_azure_blob_container(workspace=ws, 
                                                          datastore_name='my_datastore', 
                                                          container_name='my_blob_container',
                                                          account_name='my_storage_account',
                                                          account_key='your storage account key',
                                                          create_if_not_exists=True)
    
    ws.set_default_datastore('my_datastore')
    
    #upload data to datastore
    datastore.upload(src_dir='your source directory',
                     target_path='parent_dir/dir1',
                     overwrite=True,
                     show_progress=True)
    
    #download data from datastore
    datastore.download(target_path='your target path',
                       prefix='parent_dir/dir1',
                       show_progress=True)

    Regards,

    GiftA-MSFT.

    If a post helps to resolve your issue, please click “Mark as Answer” and/or “Vote as helpful”. By marking a post as Answered and/or Helpful, you help others find the answer faster.  Thanks.

    Saturday, December 7, 2019 1:47 AM