我正在尝试使用以下代码上传存储在MemoryStream中的文件。
private static void SaveStream(MemoryStream stream, string fileName)
{
var blobStorageService = new BlobStorageService();
UploadBlob(stream, fileName);
}
public void UploadBlob(MemoryStream fileStream,string fileName)
{
var blobContainer = _blobServiceClient.GetBlobContainerClient(Environment
.GetEnvironmentVariable("ContainerName"));
var blobClient = blobContainer.GetBlobClient(fileName);
blobClient.Upload(fileStream); <--- Error Message
}
错误消息:System.ArgumentException:'content.Position必须小于content.Length。请设置content.Position为要上传的数据的开头。'
答案 0 :(得分:6)
发生这种情况是因为当前位置在流的末尾。您可以在上传之前将位置设置为流的开头
var blobClient = blobContainer.GetBlobClient(fileName);
fileStream.Position =0;
blobClient.Upload(fileStream)