So far Im listing the names and creation dates of the blobs from the container in Azure Blob Storage.
Now I want to add a list of the URLs from the same blobs. I did a lot of research but I can't really find something that is of use.
Is it possible to achieve this with the same method I used for the other blob properties or is there another way?
My code:
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Azure.Storage.Blobs;
using System;
using System.Collections.Generic;
namespace getBlobData
{
// Define data transfer objects (DTO)
public class ContainerInfo
{
public string Name
{
get; set;
}
public DateTimeOffset? CreatedOn
{
get; set;
}
}
public static class GetBlobData
{
[FunctionName("getBlobData")]
public static async Task<List<ContainerInfo>> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
{
// Connect to container in storage account
// Get Blobs inside of it
string connection_string = Environment.GetEnvironmentVariable("AZURE_STORAGE_CONNECTION_STRING");
BlobServiceClient blobServiceClient = new BlobServiceClient(connection_string);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("container");
var response = containerClient.GetBlobsAsync();
// Get name and creation date of Blobs
// Return DTOs
var res = new List<ContainerInfo>();
await foreach (var item in response)
{
res.Add(new ContainerInfo { Name = item.Name, CreatedOn = item.Properties.CreatedOn });
}
return res;
}
}
}