使用AWSSDK.dll我试图在zip文件中循环播放图像,并使用下面的代码将它们发送到亚马逊S3。问题是我一直收到错误
System.Net.ProtocolViolationException
当我调用fileTransferUtility.Upload()
方法时。 zip将HttpPostedFile
发布到用于创建zip文件的方法,然后遍历每个条目并上传。
ZipFile zipFile = new ZipFile(postedFile.InputStream);
foreach (ZipEntry zipEntry in zipFile)
{
if (zipEntry.Name != String.Empty)
{
string saveLocation = unzipBaseDir + "/" + zipEntry.Name;
string dbLocation = "./" + Path.Combine(unzipBaseDir, zipEntry.Name).Replace(@"\", "/");
// save the file
TransferUtilityConfig config = new TransferUtilityConfig();
config.MinSizeBeforePartUpload = 80740;
TransferUtility fileTransferUtility = new TransferUtility(new AmazonS3Client(accessKeyID, secretAccessKeyID, RegionEndpoint.EUWest1), config);
using (Stream fileToUpload = zipFile.GetInputStream(zipEntry))
{
TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
BucketName = existingBucketName,
InputStream = fileToUpload,
StorageClass = S3StorageClass.Standard,
PartSize = fileToUpload.Length,
Key = saveLocation,
CannedACL = S3CannedACL.PublicRead
};
fileTransferUtility.Upload(fileTransferUtilityRequest);
}
}
}