public Task <IPutBlobStrategy> CreatePutBlobStrategyAsync(PutBlobRequest putBlobRequest)
        {
            putBlobRequest.ValidateArgument(nameof(putBlobRequest));

            var contentType       = (putBlobRequest.ContentType ?? defaultContentType);
            var expirationTimeUtc = DateTime.UtcNow.Add(urlDuration);

            var putBlobUrl = urlSigner.Sign(
                putBlobRequest.ContainerName,
                putBlobRequest.BlobName,
                expirationTimeUtc,
                HttpMethod.Put,
                contentHeaders: new Dictionary <string, IEnumerable <string> >
            {
                ["Content-Type"] = new[] { contentType }
            });

            var strategyConfiguration = new HttpPutBlobConfiguration
            {
                Url = putBlobUrl,
                UrlExpirationUtc = expirationTimeUtc,
                ContentType      = contentType
            };

            return(Task.FromResult(new HttpPutBlobStrategy(strategyConfiguration) as IPutBlobStrategy));
        }
Пример #2
0
        public Task <IPutBlobStrategy> CreatePutBlobStrategyAsync(PutBlobRequest putBlobRequest)
        {
            putBlobRequest.ValidateArgument(nameof(putBlobRequest));

            var container = cloudBlobClient.GetContainerReference(putBlobRequest.ContainerName.ToLower());
            var blob      = container.GetBlockBlobReference(putBlobRequest.BlobName);

            var sasStartTime      = DateTime.UtcNow.Add(urlStartOffset);
            var sasExpirationTime = DateTime.UtcNow.Add(urlDuration);

            var sasBlobPolicy = new SharedAccessBlobPolicy
            {
                SharedAccessStartTime  = sasStartTime,
                SharedAccessExpiryTime = sasExpirationTime,
                Permissions            = SharedAccessBlobPermissions.Write
            };

            var strategyConfiguration = new HttpPutBlobConfiguration
            {
                Url = (blob.Uri + blob.GetSharedAccessSignature(sasBlobPolicy)),
                UrlExpirationUtc = sasExpirationTime,
                ContentType      = (putBlobRequest.ContentType ?? defaultContentType),
                RequestHeaders   = new Dictionary <string, string>
                {
                    ["x-ms-blob-type"] = xMsBlockBlobType
                }
            };

            return(Task.FromResult(new HttpPutBlobStrategy(strategyConfiguration) as IPutBlobStrategy));
        }
Пример #3
0
        public Task <IPutBlobStrategy> CreatePutBlobStrategyAsync(PutBlobRequest putBlobRequest)
        {
            putBlobRequest.ValidateArgument(nameof(putBlobRequest));

            var contentType       = (putBlobRequest.ContentType ?? defaultContentType);
            var urlExpirationTime = DateTime.UtcNow.Add(urlDuration);

            var urlRequest = new GetPreSignedUrlRequest
            {
                BucketName  = putBlobRequest.ContainerName,
                ContentType = contentType,
                Expires     = urlExpirationTime,
                Key         = putBlobRequest.BlobName,
                Protocol    = Protocol.HTTPS,
                Verb        = HttpVerb.PUT
            };

            var strategyConfiguration = new HttpPutBlobConfiguration
            {
                Url = s3Client.GetPreSignedURL(urlRequest),
                UrlExpirationUtc = urlExpirationTime,
                ContentType      = contentType
            };

            return(Task.FromResult(new HttpPutBlobStrategy(strategyConfiguration) as IPutBlobStrategy));
        }
        public async Task <StorageStrategyDefinition> GetPutBlobStrategyDefinitionAsync(PutBlobRequest putBlobRequest)
        {
            putBlobRequest.ValidateArgument(nameof(putBlobRequest));

            var relativeUrlBuilder = new StringBuilder($"/put-blob/{putBlobRequest.ContainerName}/{putBlobRequest.BlobName}");

            if (string.IsNullOrEmpty(putBlobRequest.ContentType) == false)
            {
                relativeUrlBuilder.Append($"?contentType={putBlobRequest.ContentType}");
            }

            var relativeUrl = new Uri(relativeUrlBuilder.ToString(), UriKind.Relative);
            var response    = await httpClient.GetStringAsync(new Uri(baseUrl, relativeUrl)).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <StorageStrategyDefinition>(response));
        }
        public async Task PutBlobAsync(PutBlobRequest putBlobRequest, Stream blobStream)
        {
            putBlobRequest.ValidateArgument(nameof(putBlobRequest));

            if (blobStream == null)
            {
                throw new ArgumentNullException(nameof(blobStream));
            }

            if (blobStream.Length == 0)
            {
                throw new ArgumentException($"[{nameof(blobStream)}] can not be empty.", nameof(blobStream));
            }

            var strategyDefinition = await storageServiceProxy.GetPutBlobStrategyDefinitionAsync(putBlobRequest);

            var putBlobStrategy = await putBlobStrategyFactory.CreateStrategyAsync(strategyDefinition);

            await putBlobStrategy.PutBlobAsync(blobStream);
        }