Azure Upload Blobs To Storage account using SAS URL (source)

| By Webner

//SASToken to pass to the Blobservice client for authentication to source storage account
String sasToken = “SAS Token of source storage account ”;

//connection string to connect to the destination storage account
string connectionString =”connection string of destination storage account”;

//endpoint to pass to the blobservice client
string EndPoint = "base url of the source storage account";

//AzureSasCredential is used to authenticate to the Azure service
var credentials = new AzureSasCredential(sasTokenOfTeamUp);

//BlobServiceClient is used to manipulate resources and containers.
BlobServiceClient srcServiceClient = new BlobServiceClient(new Uri(EndPoint), credentials);

//allows you to manipulate Azure Storage containers and their blobs.
BlobContainerClient srcContainer = srcServiceClient.GetBlobContainerClient("source-container-name");

//Destination Service client to access containers and resources
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient("destination-container-name");

//loop through blobs or files of the container to upload files from source to destination
foreach (var singleblob in srcContainer.GetBlobs())
BlobBaseClient sourceBlob = srcContainer.GetBlockBlobClient(singleblob.Name);
BlobDownloadInfo download = sourceBlob.Download();
var content = download.Content;
StreamReader streamReader = new StreamReader(content);
string text-of-file = streamReader.ReadToEnd();
BlobClient blobClient = containerClient.GetBlobClient(singleblob.Name);
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(text-of-file)))
blobClient.Upload(ms, true);

Leave a Reply

Your email address will not be published. Required fields are marked *