Amazon S3 TransferUtility.Upload hangs in C#

后端 未结 2 704
故里飘歌
故里飘歌 2020-12-31 11:34

So I\'m writing a migration application, to take some data from our local storage and upload it to Amazon. Everything is working fine, except once I get into files that are

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 11:51

    Is DisplayFileProgress thread-safe? I believe (looking at some older code) that the callback is called by each upload thread independently.

    This code below is part of a small utility that we use to upload files ranging from 5 MB up to 1-2 GB or so. It's not remarkably different than yours, but perhaps it might help.

    var writerlock = new object();
    
    using (var tu = new TransferUtility(amazonS3Client, tuconfig))
    {
        var turequest = new TransferUtilityUploadRequest()
            .WithBucketName(bucket)
            .WithFilePath(file)
            .WithKey(Path.GetFileName(file))
            .WithStorageClass(S3StorageClass.ReducedRedundancy)
            .WithPartSize(5 * 1024 * 1024)
            .WithAutoCloseStream(true)
            .WithCannedACL(S3CannedACL.PublicRead);
    
        tuconfig.NumberOfUploadThreads = Environment.ProcessorCount - 1;
    
        // show progress information if not running batch
        if (interactive)
        {
            turequest.UploadProgressEvent += (s, e) =>
                                              {
                                                  lock (writerlock)
                                                  {
                                                      ... our progress routine ...
                                                  }
                                              };
        }
    
        tu.Upload(turequest);
    }
    

提交回复
热议问题