我正在尝试使用 SAS 令牌将文件/数据上传到 azure 存储。我使用以下方法成功地在没有 SAS 令牌的情况下实现了这一目标:
sendToBlob (Uint8List bytes)async {
var storage = AzureStorage.parse('DefaultEndpointsProtocol=https;AccountName=#;AccountKey=#==;EndpointSuffix=core.windows.net');
await storage.putBlob('/test/2.txt',bodyBytes: bytes);
}
当我生成 SAS 令牌并使用按以下格式编写的连接字符串时,我收到解析错误:
"BlobEndpoint=https://#.blob.core.windows.net/;QueueEndpoint=https://#.queue.core.windows.net/;FileEndpoint=https://#.file.core.windows.net/;TableEndpoint=https://#.table.core.windows.net/;SharedAccessSignature=sv=#"
尝试发送不带连接字符串的 put 请求,我的方法如下:
uploadtoAzure(String sas)async{
try {
var url = 'https://#.blob.core.windows.net/test/4.txt?'+sas;
Map<String, String> headers = ({"x-ms-blob-type": "BlockBlob"});
final response = await http.put(
url,
headers: headers,
body: 'hi'
);
print(response.statusCode);
} on DioError catch (e) {
if(e.response.statusCode == 404){
print(e.message);
}else{
print(e.message);
}
}
}
知道我是要上传到的存储帐户的所有者和存储 Blob 数据贡献者,并且 SAS 令牌未过期,这会导致 403 AuthorizationPermissionMismatch 错误。
¿<?xml version="1.0" encoding="utf-8"?><Error><Code>AuthorizationPermissionMismatch</Code><Message>This request is not authorized to perform this operation using this permission.
RequestId:bc7f5bb4-c01e-0066-0459-9a6d45000000
Time:2020-10-04T14:16:54.7302685Z</Message></Error>
有没有一种方法可以使用带有 SAS 令牌的连接字符串将数据从 flutter 上传到 azure?我怎样才能解决这个问题?
任何帮助表示赞赏。