In linux I am able to sync files like this:
https://serverfault.com/questions/682708/copy-directory-structure-intact-to-aws-s3-bucket
Now on windows using c# this is how I upload a file:
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);
}
}
How can I sync a directory instead of just uploading a file using c#?
Here is how you upload a directory to S3 using C#,
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;
}
More examples can be found from this blog,
https://www.samuelnmensah.com/blog/upload-delete-entire-directory-amazon-s3-using-transfer-utility/
Cached version of the link from google:
Hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.