简体   繁体   中英

Azure file storage unable to load files

Im trying to store a file in windows azure using their python api but get the following error:-

Error:-

azure.common.AzureMissingResourceHttpError: The specified parent path does not exist.
<?xml version="1.0" encoding="utf-8"?><Error><Code>ParentNotFound</Code><Message>The specified parent path does not exist.
RequestId:ef08c863-001a-0174-6240-e12dfd000000
Time:2017-06-09T16:47:49.6213824Z</Message></Error>

Here is the python code:-

file_service = FileService(account_name='example',                  account_key='fE0mXXgCHRqxrOdxKu9e4BI4o57E6LTUacX40n/KZNw==')
local_file_path = os.path.join(subdir, file) 
for subdir, dirs, files in os.walk(rootdir):
    for file in files:        
        result = file_service.create_file_from_path(
                    'test',
                    subdir.split(os.path.sep)[-1],
                    'testfile',
                    local_file_path,
                    # content_settings=ContentSettings(content_type='image/png')
                    )

According to your error information and the code, I think your issue is as the same as the other SO thread How to copy file from one directory to other in azure through java service? . It was caused by create a file in a nonexistent path of a share of Azure File Storage, even the parent directories or paths are not exist.

So you need to check and create these parent directories one by one from your test share to the directory kids firstly, using the method create_directory(share_name, directory_name, metadata=None, fail_on_exist=False, timeout=None) with the argument fail_on_exist=True in Python as below.

file_service = FileService(account_name='example', account_key='fE0mXXgCHRqxrOdxKu9e4BI4o57E6LTUacX40n/KZNw==')
local_file_path = os.path.join(subdir, file) 
for subdir, dirs, files in os.walk(rootdir):
    # First to check and create the parent directory whether be exist.
    file_service.create_directory('test', subdir, fail_on_exist=True)
    for file in files:        
        result = file_service.create_file_from_path(
                    'test',
                    subdir.split(os.path.sep)[-1],
                    'testfile',
                    local_file_path,
                    # content_settings=ContentSettings(content_type='image/png')
                    )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM