在linux中,我可以同步这样的文件:
https://serverfault.com/questions/682708/copy-directory-structure-intact-to-aws-s3-bucket
现在在使用c#的Windows上,这是我上传文件的方式:
using (var fileTransferUtility = new TransferUtility(_credentials.AccessKeyId, _credentials.SecretAccessKey, _region))
{
using (FileStream fileToUpload = new FileStream(fileLocation, FileMode.Open, FileAccess.Read))
{
var fileTransferUtilityRequest = new TransferUtilityUploadRequest
{
BucketName = bucketName,
InputStream = fileToUpload,
StorageClass = S3StorageClass.ReducedRedundancy,
Key = key,
CannedACL = S3CannedACL.PublicRead,
};
fileTransferUtility.Upload(fileTransferUtilityRequest);
}
}
如何同步目录而不是仅使用c#上传文件?
答案 0 :(得分:1)
以下是使用C#,
将目录上传到S3的方法try
{
TransferUtilityUploadDirectoryRequest request = new TransferUtilityUploadDirectoryRequest
{
BucketName = bucket,
Directory = uploadDirectory,
SearchOption = System.IO.SearchOption.AllDirectories,
CannedACL = S3CannedACL.PublicRead
};
_transferUtility.UploadDirectory(request);
return true;
}
catch (Exception exception)
{
//Log Exception
return false;
}
可以在此博客中找到更多示例
https://www.samuelnmensah.com/blog/upload-delete-entire-directory-amazon-s3-using-transfer-utility/
谷歌链接的缓存版本:
希望它有所帮助。