{"id":21409650,"url":"https://github.com/edgar-code-repository/spring-boot-with-azure-storage","last_synced_at":"2025-07-13T20:03:46.452Z","repository":{"id":253588751,"uuid":"843155639","full_name":"edgar-code-repository/spring-boot-with-azure-storage","owner":"edgar-code-repository","description":"Rest API that retrieves files from a blob storage container in Azure.","archived":false,"fork":false,"pushed_at":"2024-09-01T04:06:58.000Z","size":614,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-23T04:29:23.027Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edgar-code-repository.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-15T22:44:38.000Z","updated_at":"2024-09-01T04:07:01.000Z","dependencies_parsed_at":"2024-08-30T18:30:27.632Z","dependency_job_id":null,"html_url":"https://github.com/edgar-code-repository/spring-boot-with-azure-storage","commit_stats":null,"previous_names":["edgar-code-repository/spring-boot-with-azure-storage"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-with-azure-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-with-azure-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-with-azure-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edgar-code-repository%2Fspring-boot-with-azure-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edgar-code-repository","download_url":"https://codeload.github.com/edgar-code-repository/spring-boot-with-azure-storage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243910417,"owners_count":20367537,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-22T17:27:57.730Z","updated_at":"2025-03-16T17:42:51.469Z","avatar_url":"https://github.com/edgar-code-repository.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"SPRING BOOT WITH AZURE STORAGE\n---------------------------------------------------------------------------\n\n**Spring Boot REST API that retrieves files from an Azure Storage account.**\n\n---------------------------------------------------------------------------\n\n**Gradle dependency used to work with Azure:**\n\n```\n  implementation 'com.azure.spring:spring-cloud-azure-starter-storage'\n```\n\n---------------------------------------------------------------------------\n\n**Configuration class that generates the instance of BlobServiceClient\nneeded to interact with the storage container:**\n\n```\n  package com.example.demo.configuration;\n\n  import com.azure.storage.blob.BlobServiceClient;\n  import com.azure.storage.blob.BlobServiceClientBuilder;\n  import org.springframework.beans.factory.annotation.Value;\n  import org.springframework.context.annotation.Bean;\n  import org.springframework.context.annotation.Configuration;\n\n  @Configuration\n  public class BlobStorageConfiguration {\n\n    @Value(\"${connectionString}\")\n    private String connectionString;\n\n    @Bean\n    public BlobServiceClient getBlobServiceClient() {\n        return new BlobServiceClientBuilder().connectionString(connectionString).buildClient();\n    }\n\n  }\n\n```\n\n**The connection string used in the previous class is retrieved from an environment variable\n(application.properties):**\n\n```\n  connectionString=${STORAGE_CONNECTION_STRING}\n```\n\n---------------------------------------------------------------------------\n\n**A few files were uploaded to an Azure Blob Container named \"blob-container\":**\n\n![Screenshot Container](screenshots/files-in-blob-container.png)\n\n**A list of those files is read in this endpoint:**\n\n![Screenshot Postman1](screenshots/postman-files-endpoint.png)\n\n---------------------------------------------------------------------------\n\n**Code snippet that shows how to retrieve the list of elements inside the blob container:**\n\n```\n  List\u003cString\u003e filesList = new ArrayList\u003c\u003e();\n    \n  BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient(containerName);\n  for (BlobItem blobItem: blobContainerClient.listBlobs()) {\n      filesList.add(blobItem.getName());\n  }\n\n```\n\n---------------------------------------------------------------------------\n\n**Content of file \"countries_1.csv\" is retrieved as Base64 from container \"blob-container\":**\n\n![Screenshot Postman2](screenshots/postman-retrieve-content-file.png)\n\n---------------------------------------------------------------------------\n\n**Code snippet that shows how to retrieve the content of the file as Base64:**\n\n```\n  BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient(containerName);\n  BlobClient blobClient = blobContainerClient.getBlobClient(filePathAndName);\n  if (blobClient.exists()) {\n      byte[] fileContent = blobClient.downloadContent().toBytes();\n      String fileContentAsBase64 = Base64.getEncoder().encodeToString(fileContent);\n  }\n\n```\n\n---------------------------------------------------------------------------\n\n**A new blob container called \"new-container\" is created:**\n\n![Screenshot NewBlobContainer1](screenshots/new-blob-container.png)\n\n**Then, a file called \"countries.csv\" is sent to the container just created:**\n\n![Screenshot Postman3](screenshots/postman-upload-to-container.png)\n\n**Now, the file uploaded is available in the new blob container:**\n\n![Screenshot NewBlobContainer2](screenshots/container-with-uploaded-file.png)\n\n---------------------------------------------------------------------------\n\n**Code snippet to upload the content of the file as Base64:**\n\n```\n\n  BlobContainerClient blobContainerClient = blobServiceClient.getBlobContainerClient(containerName);\n  BlobClient blobClient = blobContainerClient.getBlobClient(filePathAndName);\n  byte[] decodedBytes = Base64.getDecoder().decode(fileContent);\n  ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(decodedBytes);\n  blobClient.upload(byteArrayInputStream);\n\n```\n\n---------------------------------------------------------------------------\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedgar-code-repository%2Fspring-boot-with-azure-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedgar-code-repository%2Fspring-boot-with-azure-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedgar-code-repository%2Fspring-boot-with-azure-storage/lists"}