/// <inheritdoc/> public async Task <IBackgroundTransfer> CreateAsync( IUnixDirectoryEntry targetDirectory, string fileName, Stream data, CancellationToken cancellationToken) { var targetEntry = (GoogleDriveDirectoryEntry)targetDirectory; var body = new File { Name = fileName, Parents = new List <string>() { targetEntry.File.Id, }, }; var request = Service.Files.Create(body); request.Fields = FileExtensions.DefaultFileFields; var newFileEntry = await request.ExecuteAsync(cancellationToken).ConfigureAwait(false); if (!_useBackgroundUpload) { var upload = Service.Files.Update(new File(), newFileEntry.Id, data, "application/octet-stream"); var result = await upload.UploadAsync(cancellationToken).ConfigureAwait(false); if (result.Status == UploadStatus.Failed) { throw new Exception(result.Exception.Message, result.Exception); } return(null); } var expectedSize = data.CanSeek ? data.Length : (long?)null; var tempData = await _temporaryDataFactory.CreateAsync(data, expectedSize, cancellationToken).ConfigureAwait(false); var fullPath = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName); var backgroundUploads = new BackgroundUpload(fullPath, newFileEntry, tempData, this); await _uploadsLock.WaitAsync(cancellationToken).ConfigureAwait(false); try { _uploads.Add(backgroundUploads.File.Id, backgroundUploads); } finally { _uploadsLock.Release(); } return(backgroundUploads); }
/// <inheritdoc/> public async Task <IBackgroundTransfer> CreateAsync( IUnixDirectoryEntry targetDirectory, string fileName, Stream data, CancellationToken cancellationToken) { var targetEntry = (GoogleDriveDirectoryEntry)targetDirectory; var body = new File { Name = fileName, Parents = new List <string>() { targetEntry.File.Id, }, }; var request = Service.Files.Create(body); request.Fields = FileExtensions.DefaultFileFields; var newFileEntry = await request.ExecuteAsync(cancellationToken); var expectedSize = data.CanSeek ? data.Length : (long?)null; var tempData = await _temporaryDataFactory.CreateAsync(data, expectedSize, cancellationToken); var fullPath = FileSystemExtensions.CombinePath(targetEntry.FullName, fileName); var backgroundUploads = new BackgroundUpload(fullPath, newFileEntry, tempData, this); await _uploadsLock.WaitAsync(cancellationToken); try { _uploads.Add(backgroundUploads.File.Id, backgroundUploads); } finally { _uploadsLock.Release(); } return(backgroundUploads); }