BlobItem
Namespace:
Azure.Storage.Blobs
We found 10 examples in language CSharp for this search.
You will see 37 fragments of code.
Other methods
Other methods
Project:DocumentCreator
File:ContentItemFactory.cs
Examples:2
internal static TemplateContent BuildTemplate(Uri blobUri, BlobItem blobItem, Stream contents)
{
return BuildTemplate(blobUri, blobItem.Metadata, blobItem.Properties.CreatedOn.Value.LocalDateTime, blobItem.Properties.ContentLength, contents);
}
internal static MappingContent BuildMapping(Uri blobUri, BlobItem blobItem, Stream contents)
{
return BuildMapping(blobUri,
blobItem.Metadata,
blobItem.Properties.CreatedOn.Value.LocalDateTime,
blobItem.Properties.ContentLength,
contents);
}
Project:Forky
File:BlobStore.cs
Examples:6
public int Add(byte[] stream)
{
BlobItem item = new BlobItem(stream, this);
list.Add(item);
return list.Count - 1;
}
public int AddOrUpdate(byte[] stream, string src)
{
BlobItem item = new BlobItem(stream, this);
if (!String.IsNullOrEmpty(src))
{
if (items.ContainsKey(src))
return list.IndexOf(items[src]);
else
{
item.Source = src;
items[src] = item;
}
}
list.Add(item);
return list.Count - 1;
}
public byte[] Get(int index)
{
byte[] stream = list[index].Stream;
return stream;
}
public string GetSource(int index)
{
return list[index].Source;
}
/* public Dictionary<string, byte[]> GetCache()
{
Dictionary<string, byte[]> result = new Dictionary<string, byte[]>();
foreach(BlobItem item in FList)
{
if (!String.IsNullOrEmpty(item.Source))
result[item.Source] = item.Stream;
}
return result;
}*/
public void Clear()
{
foreach (BlobItem b in list)
{
b.Dispose();
}
items.Clear();
list.Clear();
}
public void LoadDestructive(XmlItem rootItem)
{
Clear();
// avoid memory fragmentation when loading large amount of big blobs
for (int i = 0; i < rootItem.Count; i++)
{
AddOrUpdate(Convert.FromBase64String(rootItem[i].GetProp("Stream", false)),
rootItem[i].GetProp("Source"));
rootItem[i].ClearProps();
}
}
Project:JesseCarlbergProduction
File:StorageHelper.cs
Examples:6
public static bool IsImage(IFormFile file)
{
if (file.ContentType.Contains("image"))
{
return true;
}
string[] formats = new string[] { ".jpg", ".png", ".gif", ".jpeg" };
return formats.Any(item => file.FileName.EndsWith(item, StringComparison.OrdinalIgnoreCase));
}
public static async Task<bool> UploadFileToStorage(Stream fileStream, string fileName,
IAzureStorageConfig _storageConfig)
{
// Create a URI to the blob
Uri blobUri = new Uri("https://" +
_storageConfig.AccountName +
".blob.core.windows.net/" +
_storageConfig.ImageContainer +
"/" + fileName);
// Create StorageSharedKeyCredentials object by reading
// the values from the configuration (appsettings.json)
StorageSharedKeyCredential storageCredentials =
new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey);
// Create the blob client.
BlobClient blobClient = new BlobClient(blobUri, storageCredentials);
// Upload the file
await blobClient.UploadAsync(fileStream);
return await Task.FromResult(true);
}
public static async Task<bool> UploadFileToPhotoStorage(Stream fileStream, string fileName, string imageContainer,
IAzureStorageConfig _storageConfig)
{
// Create a URI to the blob
Uri blobUri = new Uri("https://" +
_storageConfig.AccountName +
".blob.core.windows.net/" +
imageContainer +
"/" + fileName);
// Create StorageSharedKeyCredentials object by reading
// the values from the configuration (appsettings.json)
StorageSharedKeyCredential storageCredentials =
new StorageSharedKeyCredential(_storageConfig.AccountName, _storageConfig.AccountKey);
// Create the blob client.
BlobClient blobClient = new BlobClient(blobUri, storageCredentials);
// Upload the file
await blobClient.UploadAsync(fileStream);
return await Task.FromResult(true);
}
public static async Task<List<string>> GetThumbNailUrls(IAzureStorageConfig _storageConfig)
{
List<string> thumbnailUrls = new List<string>();
// Create a URI to the storage account
Uri accountUri = new Uri("https://" + _storageConfig.AccountName + ".blob.core.windows.net/");
// Create BlobServiceClient from the account URI
BlobServiceClient blobServiceClient = new BlobServiceClient(accountUri);
// Get reference to the container
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(_storageConfig.ThumbnailContainer);
if (container.Exists())
{
foreach (BlobItem blobItem in container.GetBlobs())
{
thumbnailUrls.Add(container.Uri + "/" + blobItem.Name);
}
}
return await Task.FromResult(thumbnailUrls);
}
public static async Task<List<string>> GetImagesUrls(IAzureStorageConfig _storageConfig)
{
List<string> imageUrls = new List<string>();
// Create a URI to the storage account
Uri accountUri = new Uri("https://" + _storageConfig.AccountName + ".blob.core.windows.net/");
// Create BlobServiceClient from the account URI
BlobServiceClient blobServiceClient = new BlobServiceClient(accountUri);
// Get reference to the container
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(_storageConfig.ImageContainer);
if (container.Exists())
{
foreach (BlobItem blobItem in container.GetBlobs())
{
imageUrls.Add(container.Uri + "/" + blobItem.Name);
}
}
return await Task.FromResult(imageUrls);
}
public static async Task<List<string>> GetPhotoSessionImagesUrls(IAzureStorageConfig _storageConfig, string photoShoot)
{
List<string> imageUrls = new List<string>();
// Create a URI to the storage account
Uri accountUri = new Uri("https://" + _storageConfig.AccountName + ".blob.core.windows.net/");
// Create BlobServiceClient from the account URI
BlobServiceClient blobServiceClient = new BlobServiceClient(accountUri);
// Get reference to the container
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(_storageConfig.ImageContainer);
if (container.Exists())
{
foreach (BlobItem blobItem in container.GetBlobs())
{
imageUrls.Add(container.Uri + "/" + photoShoot);
}
}
return await Task.FromResult(imageUrls);
}
Project:durin-medialake
File:Form1.cs
Examples:6
private void Form1_Load(object sender, EventArgs e)
{
try
{
ListFilePathsInBlobContainer();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private async void ListFilePathsInBlobContainer()
{
//cbPaths.Items.Clear();
//clbFiles.Items.Clear();
string containerName = string.Empty;
string connStr = (string)(ConfigurationManager.AppSettings["prdhSASConnectionString"]);
BlobServiceClient blobServiceClient = new BlobServiceClient(connStr);
await foreach (BlobContainerItem blobContainerItem in blobServiceClient.GetBlobContainersAsync())
{
containerName = blobContainerItem.Name;
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(containerName);
await foreach (BlobItem blobItem in blobContainerClient.GetBlobsAsync())
{
string asset = string.Empty;
string pathBegin = string.Empty;
string name = string.Empty;
if (blobItem.Name.EndsWith(".mp4") || blobItem.Name.EndsWith(".mov"))
{
string[] pathsec = blobItem.Name.Split('/');
asset = pathsec[2];
name = blobItem.Name.Substring(blobItem.Name.IndexOf($"/{asset}/") + asset.Length + 2);
pathBegin = string.Concat(containerName, '/', blobItem.Name.Replace(name, ""));
bool isPathExists = false;
foreach (var path in cbPaths.Items)
{
if (path.Equals(pathBegin))
isPathExists = true;
}
if (isPathExists == false)
{
cbPaths.Items.Add(pathBegin);
}
}
}
}
}
private async void ListFilesInBlobContainer()
{
clbFiles.Items.Clear();
textBoxURI.Clear();
if (cbPaths.SelectedItem != null)
{
string selectedContainerName = ((string)cbPaths.SelectedItem).Split('/')[0];
string containerName = string.Empty;
string connStr = (string)(ConfigurationManager.AppSettings["prdhSASConnectionString"]);
BlobServiceClient blobServiceClient = new BlobServiceClient(connStr);
await foreach (BlobContainerItem blobContainerItem in blobServiceClient.GetBlobContainersAsync())
{
containerName = blobContainerItem.Name;
if (!(selectedContainerName.Equals(containerName)))
continue;
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient(containerName);
await foreach (BlobItem blobItem in blobContainerClient.GetBlobsAsync())
{
string show = string.Empty;
string season = string.Empty;
string episode = string.Empty;
string asset = string.Empty;
string pathBegin = string.Empty;
string name = string.Empty;
if (blobItem.Name.EndsWith(".mp4") || blobItem.Name.EndsWith(".mov"))
{
string[] pathsec = blobItem.Name.Split('/');
show = containerName;
season = pathsec[0];
episode = pathsec[1];
asset = pathsec[2];
name = blobItem.Name.Substring(blobItem.Name.IndexOf($"/{asset}/") + asset.Length + 2);
pathBegin = string.Concat(containerName, '/', blobItem.Name.Replace(name, ""));
string selectedPath = (string)cbPaths.SelectedItem;
if (selectedPath.Equals(pathBegin))
{
clbFiles.Items.Add(name);
}
}
}
}
}
}
private void cbPaths_SelectedIndexChanged(object sender, EventArgs e)
{
this.ListFilesInBlobContainer();
}
private void btnGenSecUrl_Click(object sender, EventArgs e)
{
if ( (cbPaths.SelectedItem != null) && (clbFiles.SelectedItem != null))
{
string connStr = (string)(ConfigurationManager.AppSettings["prdhSASConnectionString"]);
BlobServiceClient blobServiceClient = new BlobServiceClient(connStr);
string selectedContainerName = ((string)cbPaths.SelectedItem).Split('/')[0];
string blobItemName = string.Concat((string)cbPaths.SelectedItem,(string)clbFiles.SelectedItem);
blobItemName = blobItemName.Substring(selectedContainerName.Length + 1);
BlobClient blobClient = new BlobClient(connStr, selectedContainerName, blobItemName);
Uri sasUri = blobClient.GenerateSasUri(
Azure.Storage.Sas.BlobSasPermissions.Read | Azure.Storage.Sas.BlobSasPermissions.List,
DateTimeOffset.UtcNow.AddHours(1)
);
Console.WriteLine("SAS URI for blob is: {0}", sasUri);
textBoxURI.Text = sasUri.ToString();
this.SendMailWithSecureURI(selectedContainerName, blobItemName, sasUri.ToString());
}
}
private async void SendMailWithSecureURI(string containerName, string mediaItem, string sasUri)
{
string sendMailLAUrl = (string)(ConfigurationManager.AppSettings["SendMail_LogicApp_URL"]);
string recipient = (string)(ConfigurationManager.AppSettings["Recipient"]);
string subject = string.Empty;
string emailBody = string.Empty;
subject = $"Secure URI generated for Media File : {mediaItem} ";
emailBody = $" <br> Secure URI generated for Media File : {containerName}/{mediaItem} <br> Secure URI : {sasUri} ";
// requires using System.Net.Http;
var client = new HttpClient();
// requires using System.Text.Json;
var jsonData = JsonSerializer.Serialize(new
{
EmailBody = emailBody,
Recipient = recipient,
Subject = subject
});
HttpResponseMessage result = await client.PostAsync(
sendMailLAUrl,
new StringContent(jsonData, Encoding.UTF8, "application/json"));
var statusCode = result.StatusCode.ToString();
}
Project:ElasticSearch
File:IStorageService.cs
Examples:3
/// <summary>
/// Download file from blob storage by local path
/// </summary>
/// <param name="localPath"></param>
/// <returns>BlobItem</returns>
Task<BlobItem> DownloadFileAsync(string localPath);
/// <summary>
/// Download file from blob storage by local path
/// </summary>
/// <param name="localPath"></param>
/// <returns>BlobItem</returns>
BlobItem DownloadFile(string localPath);
/// <summary>
/// Download files from container of blob storage
/// </summary>
/// <param name="containerName">Conatiner name</param>
/// <returns>BlobItem</returns>
IEnumerable<BlobItem> DownloadFiles(string containerName = null);
Project:StorageManger
File:AzureDirectory.cs
Examples:3
public async Task<DirectoryInformation> CreateIfNotExists()
{
await Task.Run(() => cloudBlobContainer.CreateIfNotExistsAsync());
return new DirectoryInformation { Name = cloudBlobContainer.Name, Exists = true };
}
public async Task<bool> Exists()
{
return await cloudBlobContainer.ExistsAsync();
}
public async Task<List<File>> GetFiles()
{
List<File> files = new List<File>();
if (await cloudBlobContainer.ExistsAsync())
{
BlobResultSegment items = await cloudBlobContainer.ListBlobsSegmentedAsync(new BlobContinuationToken());
foreach (CloudBlockBlob blobItem in items.Results.OfType<CloudBlockBlob>())
{
files.Add(new File(Fabric.StorageType.Azure, _connectionString, _blobContainer)
{
Name = blobItem.Name,
LastWriteTime = blobItem.Properties.LastModified.HasValue ? blobItem.Properties.LastModified.Value.UtcDateTime : new System.DateTime(),
CreationTimeUtc = blobItem.Properties.Created.HasValue ? blobItem.Properties.Created.Value.UtcDateTime : new System.DateTime(),
CreationTime = blobItem.Properties.Created.HasValue ? blobItem.Properties.Created.Value.DateTime : new System.DateTime(),
});
}
}
return files;
}
Project:webapp-blob-demo
File:BlobHandler.cs
Examples:3
public Stream DownloadFile(string FileName)
{
_logger.LogInformation("Staring to download file");
BlobContainerClient container = new BlobContainerClient(connectionString, containerName);
BlobClient blob = container.GetBlobClient(FileName);
if (blob.Exists())
{
return blob.OpenRead();
}
_logger.LogError("{0} file not found!", FileName);
throw new FileNotFoundException(FileName);
}
public async Task<List<BlobModel>> GetFileList()
{
_logger.LogInformation("Starting Listing of blobs...");
BlobContainerClient container = new BlobContainerClient(connectionString, containerName);
var resultSegment = container.GetBlobsAsync().AsPages(default, 100);
List<BlobModel> list = new List<BlobModel>();
await foreach (Azure.Page<BlobItem> blobPage in resultSegment)
{
foreach (BlobItem blobItem in blobPage.Values)
{
_logger.LogInformation("Blob name: {0}", blobItem.Name);
list.Add(new BlobModel
{
BlobName = blobItem.Name,
Size = blobItem.Properties.ContentLength.GetValueOrDefault(0)
});
}
}
return list;
}
public async Task UploadFileAsync(string FileName, Stream stream)
{
_logger.LogInformation("Beginning upload for {0}", FileName);
BlobContainerClient container = new BlobContainerClient(connectionString, containerName);
BlobClient blob = container.GetBlobClient(FileName);
var info = await blob.UploadAsync(stream);
_logger.LogInformation(info.Value.ETag.ToString());
}
Project:SqlQueryNotifications
File:BlobQueryParseException.cs
Examples:1
using Azure.Storage.Blobs.Models;
using System;
namespace BlobQueryAlerts.Exceptions
{
public class BlobQueryParseException : Exception
{
public BlobQueryParseException(BlobItem blobItem, Exception innerException) : base(innerException.Message, innerException)
{
BlobItem = blobItem;
}
public BlobItem BlobItem { get; }
}
}
Project:LAEACC
File:BlobStore.cs
Examples:6
public int Add(Stream stream)
{
BlobItem item = new BlobItem(stream);
FList.Add(item);
return FList.Count - 1;
}
public Stream Get(int index)
{
Stream stream = FList[index].Stream;
if (stream != null)
stream.Position = 0;
return stream;
}
public void Clear()
{
foreach (BlobItem b in FList)
{
b.Dispose();
}
FList.Clear();
}
public void Load(XmlItem rootItem)
{
Clear();
for (int i = 0; i < rootItem.Count; i++)
{
Add(Converter.FromString(typeof(Stream), Converter.FromXml(rootItem[i].GetProp("Stream"))) as Stream);
}
}
public void Save(XmlItem rootItem)
{
foreach (BlobItem item in FList)
{
XmlItem xi = rootItem.Add();
xi.Name = "item";
xi.SetProp("Stream", Converter.ToXml(item.Stream));
}
}
public void Dispose()
{
Clear();
}
Project:MJR133
File:Index.cshtml.cs
Examples:1
public async Task OnGet()
{
var blobServiceClient =
new BlobServiceClient(_configuration["AZURE_STORAGE_CONNECTION_STRING"]);
BlobContainerClient blobContainerClient =
blobServiceClient.GetBlobContainerClient("images");
Uri uri = null;
await foreach (var blobItem in blobContainerClient.GetBlobsAsync())
{
if (_configuration["SAS_GENERATION_METHOD"] == "logicapp")
{
var url = _configuration["AZURE_LOGIC_APP_URL"];
using HttpClient client = new HttpClient();
using HttpResponseMessage res = await client.GetAsync(string.Format(_configuration["AZURE_LOGIC_APP_URL"], blobItem.Name));
using HttpContent content = res.Content;
uri = new Uri(await content.ReadAsStringAsync());
}
else
{
BlobClient blobClient = blobContainerClient.GetBlobClient(blobItem.Name);
BlobSasBuilder blobSasBuilder = new BlobSasBuilder()
{
BlobContainerName = blobContainerClient.Name,
BlobName = blobItem.Name
};
if (string.IsNullOrWhiteSpace(_configuration["AZURE_STORAGE_STORED_POLICY_NAME"]))
{
blobSasBuilder.StartsOn = DateTime.UtcNow;
blobSasBuilder.ExpiresOn = DateTime.UtcNow.AddMinutes(Convert.ToInt32(_configuration["AZURE_STORAGE_SAS_TOKEN_DURATION"]));
blobSasBuilder.SetPermissions(BlobSasPermissions.Read);
}
else
{
blobSasBuilder.Identifier = _configuration["AZURE_STORAGE_STORED_POLICY_NAME"];
}
uri = blobClient.GenerateSasUri(blobSasBuilder);
}
this.Files.Add(new FileModel() { BlobItem = blobItem, Uri = uri });
}
}
Azure.Storage.Blobs.Models.BlobItem : Object
Methods :
public String get_Name()public Boolean get_Deleted()
public String get_Snapshot()
public String get_VersionId()
public Nullable<Boolean> get_IsLatestVersion()
public BlobItemProperties get_Properties()
public IDictionary<StringString> get_Metadata()
public IDictionary<StringString> get_Tags()
public IList<ObjectReplicationPolicy> get_ObjectReplicationSourceProperties()
public Nullable<Boolean> get_HasVersionsOnly()
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()