5

I have Azure Blob and added for it Azure CDN.

How to get link to cdn for uploaded to blob file?

var storageAccount = CloudStorageAccount.Parse(configuration.ConnectionString);
var client = storageAccount.CreateCloudBlobClient();
var container = client.GetContainerReference("container");

CloudBlobContainer container = await _containerFactory.CreateAsync("files", cancellationToken);
var blockBlob = container.GetBlockBlobReference("file-name.png");

await blockBlob.UploadFromStreamAsync(fileStream, cancellationToken);

return blockBlob.Uri; // return blob blob url

blockBlob.Uri returns blob url, but I need CDN uri?

Is it possible to get CDN uri based on c# code? Without replacing part of uri to cdn endpoint.

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Anton Zimm
  • 420
  • 4
  • 14
  • 1
    You are uploading the file to a blob storage account, but you are not adding that link to the CDN, so why do you expect to receive a CDN link? – Camilo Terevinto Oct 17 '18 at 22:08
  • @CamiloTerevinto can you please explain how to do it? Please provide description step by step or some post with explanation – Anton Zimm Oct 17 '18 at 23:16
  • So you upload a file to blob storage and you want to send back the CDN url to the user ? can you not just put the CDN name into a config variable ??? – Thomas Oct 17 '18 at 23:50
  • @AntonZimm https://learn.microsoft.com/en-us/azure/cdn/cdn-app-dev-net – Camilo Terevinto Oct 18 '18 at 01:05
  • @Thomas it required to parse file uri and replace to CDN url? I don't like this solution, I try to get already correct link in response. – Anton Zimm Oct 18 '18 at 05:58
  • @CamiloTerevinto this topic about CDM managements, not about Blob and CDN work together. It is not my case – Anton Zimm Oct 18 '18 at 05:59
  • @AntonZimm, sorry trying to understand your use case... maybe there are other solution you need to think about – Thomas Oct 18 '18 at 06:46
  • 1
    Did author managed to solve it? Get cdn endpoint for a bolb? – Artyom Sep 21 '20 at 14:25
  • Did you figure this out? I'm facing the same issue. I don't know how to make blob service to return CDN endpoint URL associated to the blob. – mask8 Nov 25 '20 at 20:55

1 Answers1

0

better available solution -- concatenate strings with URL of CDN and file name

Anton Zimm
  • 420
  • 4
  • 14