/// <inheritdoc /> public override async Task <Object> UploadObjectAsync( Object destination, Stream source, UploadObjectOptions options = null, CancellationToken cancellationToken = default(CancellationToken), IProgress <IUploadProgress> progress = null) { ValidateObject(destination, nameof(destination)); GaxPreconditions.CheckNotNull(source, nameof(source)); var mediaUpload = new CustomMediaUpload(Service, destination, destination.Bucket, source, destination.ContentType); options?.ModifyMediaUpload(mediaUpload); ApplyEncryptionKey(options?.EncryptionKey, mediaUpload); if (progress != null) { mediaUpload.ProgressChanged += progress.Report; } var finalProgress = await mediaUpload.UploadAsync(cancellationToken).ConfigureAwait(false); if (finalProgress.Exception != null) { throw finalProgress.Exception; } return(mediaUpload.ResponseBody); }
/// <inheritdoc /> public override Object UploadObject( Object destination, Stream source, UploadObjectOptions options = null, IProgress <IUploadProgress> progress = null) { ValidateObject(destination, nameof(destination)); GaxPreconditions.CheckNotNull(source, nameof(source)); var mediaUpload = new CustomMediaUpload(Service, destination, destination.Bucket, source, destination.ContentType); options?.ModifyMediaUpload(mediaUpload); ApplyEncryptionKey(options?.EncryptionKey, mediaUpload); if (progress != null) { mediaUpload.ProgressChanged += progress.Report; } var finalProgress = mediaUpload.Upload(); if (finalProgress.Exception != null) { throw finalProgress.Exception; } return(mediaUpload.ResponseBody); }
internal void ModifyMediaUpload(CustomMediaUpload upload) { // Note the use of ArgumentException here, as this will basically be the result of invalid // options being passed to a public method. if (IfGenerationMatch != null && IfGenerationNotMatch != null) { throw new ArgumentException($"Cannot specify {nameof(IfGenerationMatch)} and {nameof(IfGenerationNotMatch)} in the same options", "options"); } if (IfMetagenerationMatch != null && IfMetagenerationNotMatch != null) { throw new ArgumentException($"Cannot specify {nameof(IfMetagenerationMatch)} and {nameof(IfMetagenerationNotMatch)} in the same options", "options"); } if (ChunkSize != null) { upload.ChunkSize = ChunkSize.Value; } if (PredefinedAcl != null) { upload.PredefinedAcl = GaxPreconditions.CheckEnumValue((PredefinedAclEnum)PredefinedAcl, nameof(PredefinedAcl)); } if (IfGenerationMatch != null) { upload.IfGenerationMatch = IfGenerationMatch; } if (IfGenerationNotMatch != null) { upload.IfGenerationNotMatch = IfGenerationNotMatch; } if (IfMetagenerationMatch != null) { upload.IfMetagenerationMatch = IfMetagenerationMatch; } if (IfMetagenerationNotMatch != null) { upload.IfMetagenerationNotMatch = IfMetagenerationNotMatch; } if (Projection != null) { upload.Projection = GaxPreconditions.CheckEnumValue((ProjectionEnum)Projection, nameof(Projection)); } if (UserProject != null) { upload.UserProject = UserProject; } // Note: specifying this and EncryptionKey as non-null/non-None is invalid, but that's checked in StorageClientImpl. if (KmsKeyName != null) { upload.KmsKeyName = KmsKeyName; } if (Origin != null) { upload.Options.ModifySessionInitiationRequest += message => message.Headers.Add("Origin", Origin); } }
/// <inheritdoc /> public override ObjectsResource.InsertMediaUpload CreateObjectUploader( Object destination, Stream source, UploadObjectOptions options = null) { ValidateObject(destination, nameof(destination)); GaxPreconditions.CheckNotNull(source, nameof(source)); var mediaUpload = new CustomMediaUpload(Service, destination, destination.Bucket, source, destination.ContentType); options?.ModifyMediaUpload(mediaUpload); ApplyEncryptionKey(options?.EncryptionKey, options?.KmsKeyName, mediaUpload); return(mediaUpload); }
private void ApplyEncryptionKey(EncryptionKey keyFromOptions, CustomMediaUpload upload) { var effectiveKey = keyFromOptions ?? EncryptionKey; upload.Options.ModifySessionInitiationRequest += effectiveKey.ModifyRequest; }
private void ApplyEncryptionKey(EncryptionKey keyFromOptions, string kmsNameFromOptions, CustomMediaUpload upload) { var effectiveKey = GetEffectiveEncryptionKey(keyFromOptions, kmsNameFromOptions); upload.Options.ModifySessionInitiationRequest += effectiveKey.ModifyRequest; }