【发布时间】:2018-08-13 11:07:51
【问题描述】:
我得到的错误是:
The thread 0xffc has exited with code 0 (0x0).
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in Anjuna1.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware:Error: An unhandled exception has occurred: The write operation failed, see inner exception.
System.IO.IOException: The write operation failed, see inner exception. --->
System.Net.Http.WinHttpException: The connection with the server was
terminated abnormally
--- End of inner exception stack trace ---
完整的堆栈跟踪在这里:https://pastebin.com/BGny5ULG
代码(.net core 2)如下:
private async Task S3UploadFileAsync(string fileName, Stream stream)
{
using (IAmazonS3 client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest2))
{
var uploadRequest = new TransferUtilityUploadRequest
{
InputStream = stream,
BucketName = "******-*****",
CannedACL = S3CannedACL.AuthenticatedRead,
Key = fileName
};
TransferUtility fileTransferUtility = new TransferUtility(client);
try
{
await fileTransferUtility.UploadAsync(uploadRequest);
}
catch (System.Exception e)
{
throw e;
}
}
}
上面的代码在我的本地机器(Windows 10)上运行良好,但在 EC2 实例(Windows Server 2016)上运行良好。
我尝试公开 S3 存储桶,认为这是权限问题(仍然无法正常工作)。
我认为这可能是 Windows 防火墙或 EC“实例安全组的问题,因此我安装了 AWS CLI 并可以使用它上传到 S3 实例而没有问题。
无论我上传什么,我都尝试过大文件、小文件甚至空文件。
在捕获异常之前大约需要 30 秒,所以感觉有些东西正在超时。将代码更改为不存在的 BucketName 会导致相同的症状,使我认为这与存储桶配置无关(我已将名称标出)。
如有任何关于尝试的建议的帮助,我们将不胜感激 - 我整天都在努力,但我的想法已经用完了......谢谢!
更新:这里的类似错误表明它与权限相关:https://matt40k.uk/2017/09/s3-errors/
【问题讨论】:
-
更新部分拯救了我的一天:我得到了错误的密钥/秘密组合。谢谢,伙计!
标签: .net amazon-s3 aws-sdk asp.net-core-2.0 awss3transferutility