簡體   English   中英

帶有Amazon S3存儲桶的AWS Sync文件

[英]AWS Sync files with amazon s3 bucket

在linux中,我能夠像這樣同步文件:

https://serverfault.com/questions/682708/copy-directory-structure-intact-to-aws-s3-bucket

現在在Windows上使用C#,這就是我上傳文件的方式:

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#上傳文件?

這是使用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/

谷歌鏈接的緩存版本:

http://webcache.googleusercontent.com/search?q=cache:b1CN7MxwkLwJ:samuelnmensah.com/uploading-and-deleting-an-entire-directory-to-aws-s3-using-transfer-utility/+&cd=1&hl = en&ct = clnk&gl = us

希望能幫助到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM