Teo*_*ahi 0 c# azure azure-storage azure-storage-blobs azure-sdk
我有以下代码将文件上传到我的 Azure 存储:
读取文件流如下:
FileStream fileStream = File.OpenRead(filePath);
Run Code Online (Sandbox Code Playgroud)
并传递给函数 =>
public async Task<Response<BlobContentInfo>> UploadBlob(string containerName, string blobName, Stream stream, string contentType,
IDictionary<string, string> metadata = null)
{
IDictionary<string, string> metadataEncoded = new Dictionary<string, string>();
if (metadata != null)
{
foreach (KeyValuePair<string, string> keyValuePair in metadata)
{
string encodedValue = TextUtilities.Base64Encode(keyValuePair.Value);
metadataEncoded.Add(keyValuePair.Key, encodedValue);
}
}
await using (stream)
{
BlobClient blobClient = GetBlobClient(containerName, blobName);
BlobHttpHeaders httpHeaders = new BlobHttpHeaders { ContentType = contentType };
BlobRequestConditions conditions = new BlobRequestConditions();
Response<BlobContentInfo> uploadAsync = await blobClient.UploadAsync(stream, httpHeaders, metadataEncoded, conditions);
stream.Close();
return uploadAsync;
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试上传像这个示例 pdf => http://www.africau.edu/images/default/sample.pdf这样的任意文件,它工作正常。但是出于某种原因,如果我尝试上传本页中的 pdf 文件 =>
https://docs.microsoft.com/en-us/dotnet/core/
Dot.NET Core Documentation PDF
我收到以下异常:
Inner Exception 1:
HttpRequestException: Error while copying content to a stream.
Inner Exception 2:
IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request..
Inner Exception 3:
SocketException: The I/O operation has been aborted because of either a thread exit or an application request.
Run Code Online (Sandbox Code Playgroud)
我不认为这与文件大小有关,因为我还尝试了其他一些大尺寸的 .pdf 文件,它们被推送到 Azure 存储。
我在这里遗漏了一些具体的东西吗?我还从https://docs.microsoft.com/en-us/azure/sql-database/下载了 .pdf并从该行收到了相同的错误await blobClient.UploadAsync()
注意:作为参考,我发现了这个开放的 GitHub 问题,但尚未解决。 https://github.com/Azure/azure-sdk-for-net/issues/9212
| 归档时间: |
|
| 查看次数: |
1403 次 |
| 最近记录: |