예제 #1
0
        public async Task <string> GetBlobSasAsync(
            string fullPath,
            BlobSasPolicy blobSasPolicy         = null,
            bool includeUrl                     = true,
            CancellationToken cancellationToken = default)
        {
            if (blobSasPolicy == null)
            {
                blobSasPolicy = new BlobSasPolicy(DateTime.UtcNow, TimeSpan.FromHours(1))
                {
                    Permissions = BlobSasPermission.Read
                }
            }
            ;

            (BlobContainerClient container, string path) = await GetPartsAsync(fullPath, false).ConfigureAwait(false);

            string sas = blobSasPolicy.ToSasQuery(_sasSigningCredentials, container.Name, path);

            if (includeUrl)
            {
                string url = _client.Uri.ToString();
                url += StoragePath.Normalize(fullPath);
                url += "?";
                url += sas;
                return(url);
            }

            return(sas);
        }
        public async Task <string> GetBlobSasAsync(
            string fullPath, BlobSasPolicy blobSasPolicy,
            bool includeUrl = true, CancellationToken cancellationToken = default)
        {
            (CloudBlobContainer container, string relativePath) = await GetPartsAsync(fullPath, false).ConfigureAwait(false);

            if (container == null)
            {
                return(null);
            }

            CloudBlockBlob blob = container.GetBlockBlobReference(relativePath);

            blobSasPolicy ??= new BlobSasPolicy(TimeSpan.FromHours(1));

            string sas = blob.GetSharedAccessSignature(blobSasPolicy.ToSharedAccessBlobPolicy());

            if (includeUrl)
            {
                sas = blob.Uri + sas;
            }

            return(sas);
        }