Esempio n. 1
0
        public string GetBlobSasUrl(string containerName, string blobName, DateTimeOffset expiry, bool isDownload = false,
                                    string filename = null, string contentType = null, BlobUrlAccess access = BlobUrlAccess.Read)
        {
            var blob = _blobClient.GetContainerReference(containerName)
                       .GetBlockBlobReference(blobName);

            var builder     = new UriBuilder(blob.Uri);
            var headers     = new SharedAccessBlobHeaders();
            var hasFilename = !string.IsNullOrEmpty(filename);

            if (hasFilename || isDownload)
            {
                headers.ContentDisposition = "attachment" + (hasFilename ? "; filename=\"" + filename + "\"" : string.Empty);
            }

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

            builder.Query = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions            = access.ToPermissions(),
                SharedAccessStartTime  = DateTimeOffset.UtcNow.AddMinutes(-5),
                SharedAccessExpiryTime = expiry,
            }, headers).TrimStart('?');

            return(builder.Uri.ToString());
        }
        public string GetBlobSasUrl(string containerName, string blobName, DateTimeOffset expiry, bool isDownload = false, 
            string filename = null, string contentType = null, BlobUrlAccess access = BlobUrlAccess.Read)
        {
            var blob = _blobClient.GetContainerReference(containerName)
                .GetBlockBlobReference(blobName);

            var builder = new UriBuilder(blob.Uri);
            var headers = new SharedAccessBlobHeaders();
            var hasFilename = !string.IsNullOrEmpty(filename);

            if (hasFilename || isDownload)
            {
                headers.ContentDisposition = "attachment" + (hasFilename ? "; filename=\"" + filename + "\"" : string.Empty);
            }

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

            builder.Query = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions = access.ToPermissions(),
                SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5),
                SharedAccessExpiryTime = expiry,
            }, headers).TrimStart('?');

            return builder.Uri.ToString();
        }