コード例 #1
0
 /// <inheritdoc/>
 public async Task Start(CancellationToken cancellationToken)
 {
     using (var stream = await _tempData.OpenAsync())
     {
         try
         {
             await _fileSystem.Service.UploadAsync(File.Id, stream, "application/octet-stream", cancellationToken);
         }
         finally
         {
             _notifiedAsFinished = true;
             _fileSystem.UploadFinished(File.Id);
         }
     }
 }
コード例 #2
0
ファイル: BackgroundUpload.cs プロジェクト: slogen/FtpServer
        /// <inheritdoc />
        public async Task Start(IProgress <long> progress, CancellationToken cancellationToken)
        {
            using (var stream = await _tempData.OpenAsync())
            {
                try
                {
                    var upload = _fileSystem.Service.Files.Update(new File(), File.Id, stream, "application/octet-stream");
                    upload.ProgressChanged += (uploadProgress) => { progress.Report(uploadProgress.BytesSent); };
                    var result = await upload.UploadAsync(cancellationToken);

                    if (result.Status == UploadStatus.Failed)
                    {
                        throw new Exception(result.Exception.Message, result.Exception);
                    }
                }
                finally
                {
                    _notifiedAsFinished = true;
                    _fileSystem.UploadFinished(File.Id);
                }
            }
        }