public async Task Start(CancellationToken cancellationToken) { using (var stream = await _tempData.OpenAsync()) { bool withError = false; try { Item = await _fileSystem.Service.UploadFileAsync(_fileSystem.Drive.Id, ParentId, Name, stream, cancellationToken); } catch (OperationCanceledException) { withError = true; if (Item == null) { throw new InvalidOperationException("The Item property must be set. The UploadFileAsync function must not return a NULL value."); } Item.Size = stream.Position; throw; } finally { _notifiedAsFinished = true; await _fileSystem.UploadFinished(ParentId, Name, withError); } } }
/// <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); } } }
/// <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); } } }