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();
}
}