Beispiel #1
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 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));
        }
Beispiel #3
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));
        }