コード例 #1
0
        public Task <IGetBlobStrategy> CreateGetBlobStrategyAsync(GetBlobRequest getBlobRequest)
        {
            getBlobRequest.ValidateArgument(nameof(getBlobRequest));

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

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

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

            var strategyConfiguration = new HttpGetBlobConfiguration
            {
                Url = (blob.Uri + blob.GetSharedAccessSignature(sasBlobPolicy)),
                UrlExpirationUtc = sasExpirationTime
            };

            return(Task.FromResult(new HttpGetBlobStrategy(strategyConfiguration) as IGetBlobStrategy));
        }
コード例 #2
0
        public async Task <StorageStrategyDefinition> GetGetBlobStrategyDefinitionAsync(GetBlobRequest getBlobRequest)
        {
            getBlobRequest.ValidateArgument(nameof(getBlobRequest));

            var relativeUrl = new Uri($"/get-blob/{getBlobRequest.ContainerName}/{getBlobRequest.BlobName}", UriKind.Relative);
            var response    = await httpClient.GetStringAsync(new Uri(baseUrl, relativeUrl)).ConfigureAwait(false);

            return(JsonConvert.DeserializeObject <StorageStrategyDefinition>(response));
        }
コード例 #3
0
        public async Task <Stream> GetBlobAsync(GetBlobRequest getBlobRequest)
        {
            getBlobRequest.ValidateArgument(nameof(getBlobRequest));

            var strategyDefinition = await storageServiceProxy.GetGetBlobStrategyDefinitionAsync(getBlobRequest);

            var getBlobStrategy = await getBlobStrategyFactory.CreateStrategyAsync(strategyDefinition);

            return(await getBlobStrategy.GetBlobAsync());
        }
        public Task <IGetBlobStrategy> CreateGetBlobStrategyAsync(GetBlobRequest getBlobRequest)
        {
            getBlobRequest.ValidateArgument(nameof(getBlobRequest));

            var expirationTimeUtc = DateTime.UtcNow.Add(urlDuration);

            var getBlobUrl = urlSigner.Sign(
                getBlobRequest.ContainerName,
                getBlobRequest.BlobName,
                expirationTimeUtc,
                HttpMethod.Get);

            var strategyConfiguration = new HttpGetBlobConfiguration
            {
                Url = getBlobUrl,
                UrlExpirationUtc = expirationTimeUtc
            };

            return(Task.FromResult(new HttpGetBlobStrategy(strategyConfiguration) as IGetBlobStrategy));
        }
コード例 #5
0
        public Task <IGetBlobStrategy> CreateGetBlobStrategyAsync(GetBlobRequest getBlobRequest)
        {
            getBlobRequest.ValidateArgument(nameof(getBlobRequest));

            var urlExpirationTime = DateTime.UtcNow.Add(urlDuration);

            var urlRequest = new GetPreSignedUrlRequest
            {
                BucketName = getBlobRequest.ContainerName,
                Expires    = urlExpirationTime,
                Key        = getBlobRequest.BlobName,
                Protocol   = Protocol.HTTPS,
                Verb       = HttpVerb.GET
            };

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

            return(Task.FromResult(new HttpGetBlobStrategy(strategyConfiguration) as IGetBlobStrategy));
        }