Example #1
0
        private StreamInterceptor CreateInterceptor(HttpResponseMessage response)
        {
            crc32cHashBase64 = null;
            hasher           = null;

            IEnumerable <string> values;

            if (response.Headers.TryGetValues(Crc32c.HashHeaderName, out values))
            {
                string prefix = Crc32c.HashName + "=";
                foreach (var value in values.SelectMany(v => v.Split(',')))
                {
                    if (value.StartsWith(prefix))
                    {
                        hasher           = new Crc32c();
                        crc32cHashBase64 = value.Substring(prefix.Length);
                        return(hasher.UpdateHash);
                    }
                }
            }
            return(null);
        }
Example #2
0
        protected override void OnResponseReceived(HttpResponseMessage response)
        {
            base.OnResponseReceived(response);

            crc32cHashBase64 = null;
            hasher           = null;

            IEnumerable <string> values;

            if (response.Headers.TryGetValues(Crc32c.HashHeaderName, out values))
            {
                string prefix = Crc32c.HashName + "=";
                foreach (var value in values.SelectMany(v => v.Split(',')))
                {
                    if (value.StartsWith(prefix))
                    {
                        hasher           = new Crc32c();
                        crc32cHashBase64 = value.Substring(prefix.Length);
                        break;
                    }
                }
            }
        }
Example #3
0
            internal UploadHelper(
                StorageClient client,
                Object destination,
                Stream source,
                UploadObjectOptions options,
                IProgress <IUploadProgress> progress)
            {
                _client      = client;
                _mediaUpload = client.CreateObjectUploader(destination, source, options);
                if (progress != null)
                {
                    _mediaUpload.ProgressChanged += progress.Report;
                }

                var validationMode = options?.UploadValidationMode ?? UploadObjectOptions.DefaultValidationMode;

                GaxPreconditions.CheckEnumValue(validationMode, nameof(UploadObjectOptions.UploadValidationMode));
                switch (validationMode)
                {
                case UploadValidationMode.DeleteAndThrow:
                    _crc = new Crc32c();
                    _mediaUpload.UploadStreamInterceptor += _crc.UpdateHash;
                    _validationFailureAction              = obj => client.DeleteObject(obj, new DeleteObjectOptions {
                        Generation = obj.Generation
                    });
                    _validationFailureAsyncAction = (obj, token) => client.DeleteObjectAsync(obj, new DeleteObjectOptions {
                        Generation = obj.Generation
                    }, token);
                    break;

                case UploadValidationMode.ThrowOnly:
                    _crc = new Crc32c();
                    _mediaUpload.UploadStreamInterceptor += _crc.UpdateHash;
                    break;
                }
            }