[英]Error when trying to upload file to Azure File Share
我正在尝试将 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);
}
}
其中内容是上面的 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
内容类型:应用程序/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);
}
}
如果要复制代码:
//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);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.