/// <summary>
 /// A set of response headers that should be returned with the object.
 /// </summary>
 /// <param name="responseHeaderOverrides">Response headers to return</param>
 /// <returns>this instance</returns>
 public GetObjectRequest WithResponseHeaderOverrides(ResponseHeaderOverrides responseHeaderOverrides)
 {
     this.ResponseHeaderOverrides = responseHeaderOverrides;
     return(this);
 }
 public GetPreSignedUrlRequest WithResponseHeaderOverrides(ResponseHeaderOverrides responseHeaderOverrides)
 {
     this.ResponseHeaderOverrides = responseHeaderOverrides;
     return(this);
 }
 public GetPreSignedUrlRequest WithResponseHeaderOverrides(ResponseHeaderOverrides responseHeaderOverrides)
 {
     this.ResponseHeaderOverrides = responseHeaderOverrides;
     return this;
 }
 /// <summary>
 /// Sets the ResponseHeaderOverrides property and returns back this instance for method chaining.
 /// </summary>
 /// <param name="responseHeaderOverrides">The response headers</param>
 /// <returns>this instance</returns>
 public GetObjectRequest WithResponseHeaderOverrides(ResponseHeaderOverrides responseHeaderOverrides)
 {
     this.ResponseHeaderOverrides = responseHeaderOverrides;
     return this;
 }
Esempio n. 5
0
        public override Uri GetUri(string domain, string path, TimeSpan expire, IEnumerable<string> headers)
        {
            if (expire == TimeSpan.Zero || expire == TimeSpan.MinValue || expire == TimeSpan.MaxValue)
            {
                expire = GetExpire(domain);
            }
            if (expire == TimeSpan.Zero || expire == TimeSpan.MinValue || expire == TimeSpan.MaxValue)
            {
                return GetUriShared(domain, path);
            }

            var pUrlRequest = new GetPreSignedUrlRequest()
                .WithBucketName(_bucket)
                .WithExpires(DateTime.UtcNow.Add(expire))
                .WithKey(MakePath(domain, path))
                .WithProtocol(SecureHelper.IsSecure() ? Protocol.HTTPS : Protocol.HTTP)
                .WithVerb(HttpVerb.GET);

            if (headers != null && headers.Any())
            {
                var headersOverrides = new ResponseHeaderOverrides();
                foreach (var h in headers)
                {
                    if (h.StartsWith("Content-Disposition")) headersOverrides.WithContentDisposition(h.Substring("Content-Disposition".Length + 1));
                    else if (h.StartsWith("Cache-Control")) headersOverrides.WithCacheControl(h.Substring("Cache-Control".Length + 1));
                    else if (h.StartsWith("Content-Encoding")) headersOverrides.WithContentEncoding(h.Substring("Content-Encoding".Length + 1));
                    else if (h.StartsWith("Content-Language")) headersOverrides.WithContentLanguage(h.Substring("Content-Language".Length + 1));
                    else if (h.StartsWith("Content-Type")) headersOverrides.WithContentType(h.Substring("Content-Type".Length + 1));
                    else if (h.StartsWith("Expires")) headersOverrides.WithExpires(h.Substring("Expires".Length + 1));
                    else throw new FormatException(string.Format("Invalid header: {0}", h));
                }
                pUrlRequest.WithResponseHeaderOverrides(headersOverrides);
            }

            return MakeUri(GetClient().GetPreSignedURL(pUrlRequest));
        }
        public string GetBlobSasUrl(string containerName, string blobName, DateTimeOffset expiry, bool isDownload = false,
            string fileName = null, string contentType = null, BlobUrlAccess access = BlobUrlAccess.Read)
        {
            var headers = new ResponseHeaderOverrides();

            if (isDownload)
            {
                headers.ContentDisposition = "attachment;";
            }

            if (!string.IsNullOrEmpty(fileName))
            {
                headers.ContentDisposition += "filename=\"" + fileName + "\"";
            }

            if (!string.IsNullOrEmpty(contentType))
            {
                headers.ContentType = contentType;
            }

            var urlRequest = new GetPreSignedUrlRequest()
            {
                BucketName = _bucket,
                Key = GenerateKeyName(containerName, blobName),
                Expires = expiry.UtcDateTime,
                ResponseHeaderOverrides = headers,
                Verb = access == BlobUrlAccess.Read ? HttpVerb.GET : HttpVerb.PUT
            };

            try
            {
                return _s3Client.GetPreSignedURL(urlRequest);
            }
            catch (AmazonS3Exception asex)
            {
                throw asex.ToStorageException();
            }
        }