我正在尝试将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>
上传内容的方法如下:
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);
}
}
其中content是上面的xml字符串,路径是/ orders / fromwebshop,这是文件共享上的现有文件夹,名称是order-1.xml。
错误:
Windows-Azure-File / 1.0,Microsoft-HTTPAPI / 2.0
x-ms-error-code:InvalidRange
日期:星期四,2020年9月24日格林尼治标准时间
内容长度: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);
}
}
答案 0 :(得分:0)
如果要复制代码:
//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);
}
}