上个月,我们将Amazon AWSSDK nuget软件包从版本2.3更新为3.1。之后,没有任何文件被上传到服务器,但我没有收到任何错误。我试图访问我得到404的位置或带有0bytes的文件
这是代码。我错过了什么?
var keyName = Globals.configSettings.AmazonS3ApiKey;
var apiId = Globals.configSettings.AmazonS3ApiId;
var fileName = !string.IsNullOrEmpty(ChangedFileName) ? ChangedFileName : fileUploadDownloadable.FileName;
using (var fileTransferUtility = new TransferUtility(new AmazonS3Client(apiId, keyName, Amazon.RegionEndpoint.USEast1)))
{
var bucketName = Globals.configSettings.AmazonS3ApiBucketName;
var request = new TransferUtilityUploadRequest
{
BucketName = bucketName,
Key = "images/downloads/" + fileName,
InputStream = fileUploadDownloadable.PostedFile.InputStream
};
fileTransferUtility.Upload(request);
}
感谢您的帮助!
答案 0 :(得分:0)
出于某种原因,当我将代码更改为此时,它开始工作..我不知道为什么
var keyName = Globals.configSettings.AmazonS3ApiKey;
var apiId = Globals.configSettings.AmazonS3ApiId;
var fileName = !string.IsNullOrEmpty(ChangedFileName) ? ChangedFileName : fileUploadDownloadable.FileName;
using (var fileTransferUtility = new TransferUtility(new AmazonS3Client(apiId, keyName, Amazon.RegionEndpoint.USEast1)))
{
var bucketName = Globals.configSettings.AmazonS3ApiBucketName;
var inputStream = new MemoryStream(File.ReadAllBytes(filePath));
var key = "images/downloads/" + fileName;
fileTransferUtility.Upload(inputStream, bucketName, key);
}