sin*_*rem 5 c# xml file-upload azure
我尝试将 xml 文件上传到存储帐户中的 Azure 文件共享,但不断收到此错误:
指定的范围对于资源的当前大小无效。
我可以从同一共享下载文件,因此连接本身可以正常工作
我创建了一个 xml 文件,如下所示:
<?xml version="1.0" encoding="utf-16"?>
<WebOrderList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<WebOrder>
<OrderId>1</OrderId>
<Info>info about order</Info>
<Description>testing</Description>
<WebItemListWebItem>
<ItemNo>321</ItemNo>
<ParentID>0</ParentID>
</WebItemListWebItem>
</WebOrder>
</WebOrderList>
Run Code Online (Sandbox Code Playgroud)
上传内容的方法如下所示:
public async Task UploadFile(string content, string path, string name)
{
var fileClient = new ShareFileClient(_connectionString, _shareName, path);
byte[] byteArray = Encoding.UTF8.GetBytes(content);
using (var stream = new MemoryStream(byteArray))
{
await fileClient.UploadAsync(stream);
}
}
Run Code Online (Sandbox Code Playgroud)
其中内容是上面的 xml 字符串,路径是 /orders/fromwebshop,它是文件共享上的现有文件夹,名称是 order-1.xml。
错误:
Windows-Azure-File/1.0、Microsoft-HTTPAPI/2.0
x-ms-错误代码:无效范围
日期:2020 年 9 月 24 日星期四 06:39:39 GMT
内容长度:249
内容类型:application/xml
如果你想复制:
//ExampleData
//Content = string as Xml.
//Path = "$"/orders/fromwebshop""
//Name = "$"order-{order.WebOrder[0].OrderId}.xml"
public async Task UploadFile(string content, string path, string name)
{
var newMove = new ShareFileClient(_connectionString, _shareName, $"{path}/{name}");
byte[] byteArray = Encoding.UTF8.GetBytes(content);
await newMove.CreateAsync(byteArray.Length);
using (var stream = new MemoryStream(byteArray))
{
await newMove.UploadAsync(stream);
}
}
Run Code Online (Sandbox Code Playgroud)
如果你想复制代码:
//ExampleData
//Content = string as Xml.
//Path = "$"/orders/fromwebshop""
//Name = "$"order-{order.WebOrder[0].OrderId}.xml"
public async Task UploadFile(string content, string path, string name)
{
var newMove = new ShareFileClient(_connectionString, _shareName, $"{path}/{name}");
byte[] byteArray = Encoding.UTF8.GetBytes(content);
await newMove.CreateAsync(byteArray.Length);
using (var stream = new MemoryStream(byteArray))
{
await newMove.UploadAsync(stream);
}
}
Run Code Online (Sandbox Code Playgroud)