我正在使用适用于 .NET 1.5.9.0 的 AWS 开发工具包并进行了更改
var putObjectRequest = new PutObjectRequest
{
BucketName = bucketName,
Key = key,
FilePath = filePath,
CannedACL = S3CannedACL.PublicRead
};
try
{
using (var pubtObjectResponse = client.PutObject(putObjectRequest))
{
Logger.Application.DebugFormat("uploaded {0} to {1} on bucket {2}, got id {3}", filePath, remotePath, bucketName, pubtObjectResponse.AmazonId2);
}
}
catch (Exception ex)
{
Logger.Application.Fatal(string.Format("could not upload {0} to {1} on bucket {2}", filePath, remotePath, bucketName), ex);
}
由于
System.Net.WebException:请求被中止:请求被取消。--->
System.IO.IOException:在写入所有字节之前无法关闭流。
在 System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
--- 内部异常堆栈跟踪结束 ---
在 System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
在 System.Net.ConnectStream.System .Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.ConnectStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at Amazon.S3.AmazonS3Client.getRequestStreamCallback[T](IAsyncResult result)
at Amazon。 S3.AmazonS3Client.endOperation[T](IAsyncResult 结果)
在 Amazon.S3.AmazonS3Client.EndPutObject(IAsyncResult asyncResult)
通过建议_
var transferUtilityUploadRequest = new TransferUtilityUploadRequest()
.WithBucketName(bucketName)
.WithKey(key)
.WithFilePath(filePath)
.WithCannedACL(S3CannedACL.PublicRead);
try
{
transferUtility.Upload(transferUtilityUploadRequest);
// how do I get success-state in here?
// how do I get AmazonId2 in here?
}
catch (Exception ex)
{
Logger.Application.Fatal(string.Format("could not upload {0} to {1} on bucket {2}", filePath, remotePath, bucketName), ex);
}
很明显我要做什么,但我如何访问所需的信息?谁能指出我正确的方向?