Python — загрузка файла C ++ Azure: серверу не удалось аутентифицировать запрос

Я пытаюсь загрузить файл в мою файловую службу Azure, используя следующий код C ++ (на который есть ссылка в официальной документации Вот):

const utility::string_t storage_connection_string(U("DefaultEndpointsProtocol=https;AccountName=myaccount;""AccountKey=mykey"));

// Retrieve storage account from connection string.
azure::storage::cloud_storage_account storage_account =
azure::storage::cloud_storage_account::parse(storage_connection_string);

// Create the Azure Files client.
azure::storage::cloud_file_client file_client =
storage_account.create_cloud_file_client();

// Get a reference to the share.
azure::storage::cloud_file_share share =
file_client.get_share_reference(_XPLATSTR("myfileservice"));

//Get a reference to the root directory for the share.
azure::storage::cloud_file_directory root_dir = share.get_root_directory_reference();

// Upload a file from a file.
azure::storage::cloud_file file =
root_dir.get_file_reference(_XPLATSTR("my-sample-file"));
file.upload_from_file(_XPLATSTR("test.pdf"));

Это выдает следующую ошибку:

terminate called after throwing an instance of 'azure::storage::storage_exception'

what():  Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.

Я искал в Интернете и обнаружил, что это должно быть связано с аутентификацией с использованием SAS. Я попробовал много примеров кодов онлайн, но все еще не может преуспеть.

Тем не менее, я могу сделать аналогичную загрузку файла следующим питон код without SAS authentication и без проблем

import os
from azure.storage.file import FileService, ContentSettings

currentDir = os.path.dirname(os.path.abspath(__file__))

#credentials for azure account
file_service = FileService(account_name='myaccount', account_key='mykey')

#path for azure file
global pathStr
pathStr = 'https://myaccount.file.core.windows.net/myfileservice/'

#function for uploading file onto Azure container
def upload(myfile):
file_service.create_file_from_path(
'myfileservice',
'files',
test + '.pdf',
myfile,
content_settings=ContentSettings(content_type='text/pdf')
)
print('finished uploading file.')

Что может быть решением для этого?

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector