hakdogan / azure-storage-account

This repository is a tutorial about how to serve Azure Storage Resources with grant limited access using SAS in a declarative way

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to Serve Azure Storage Resources with Grant Limited Access using SAS?

Azure Blob Storage is Microsoft's object storage solution that allows you to store a massive amount of unstructured data. It is a good solution for needs such as streaming video and audio, serving images or documents directly to a browser, etc, as they are accessible using REST APIs. This repository shows you how to serve Azure Storage Resources with grant limited access using SAS in a declarative way.

    public String generateAccessUrlWithSAS(final String containerName, final String blobName,
                                           final int amount, final ChronoUnit chronoUnit) {
        var blobContainerSasPermission = new BlobContainerSasPermission().setReadPermission(true);
        var builder = new BlobServiceSasSignatureValues(OffsetDateTime.now().plus(amount, chronoUnit),
                blobContainerSasPermission).setProtocol(SasProtocol.HTTPS_ONLY);

        var client = getBlobClient(connectionString, containerName, blobName);

        return client.exists()?String.format("https://%s.blob.core.windows.net/%s/%s?%s", client.getAccountName(),
                client.getContainerName(), blobName, client.generateSas(builder)):"Resource not found";
    }

Requirements

  • JDK 12 or later

How to run

mvn spring-boot:run

Relecant article is

How to Serve Azure Storage Resources with Grant Limited Access using SAS?

About

This repository is a tutorial about how to serve Azure Storage Resources with grant limited access using SAS in a declarative way


Languages

Language:Java 96.3%Language:Shell 3.7%