You don't have access to this class

Keep learning! Join and start boosting your career

Aprovecha el precio especial y haz tu profesi贸n a prueba de IA

Antes: $249

Currency
$209
Suscr铆bete

Termina en:

1 D铆as
4 Hrs
9 Min
39 Seg

Crear contenedores en Blob Storage con .NET Core

9/22
Resources

How to secure the connection string in your application?

Securing your connection string is crucial to ensure the security of your database. Make sure you copy the string from the portal and verify its visibility. Here we will show you how to do it step by step.

  • Log in to the portal and locate the connection string under "Access Keys".
  • Copy the connection string making sure that it is not visible to unauthorized users.
  • Save the string in a secure storage to prevent it from being accidentally shared.

How to integrate the Azure Blob Storage library?

Once the connection string is secure, it is time to integrate the Azure Blob Storage library into your project. This will allow you to interact with your data effectively.

  1. Use the Microsoft.Azure.Storage.Blob package to manage the blobs.
  2. Add the necessary statements to extend your code:
    using Microsoft.Azure.Storage;using Microsoft.Azure.Storage.Blob;

How to establish a connection using C#?

Having already the connection string and the integrated library, it is time to establish the connection to manage your data in Azure Blob Storage.

  1. Create a storage account using the following code:
    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
  2. Initializes the blobs client:
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

How to create a container in Azure Blob Storage?

A container functions as a folder or directory within Blob Storage, where the blobs will be stored.

  1. Define the container with the following code:
    CloudBlobContainer container = blobClient.GetContainerReference("container_name");
  2. Create the container if it does not exist:
    container.CreateIfNotExists();

How to set public permissions on your container?

Setting permissions on your container is paramount for accessing files from the browser.

  • Use the SetPermissions method to define public access:
    BlobContainerPermissions permissions = new BlobContainerPermissions{ PublicAccess = BlobContainerPublicAccessType.Blob};container.SetPermissions(permissions);

Practical tips to avoid common mistakes

  • Avoid using uppercase letters in container names to prevent execution errors.
  • Be sure to always save changes to your code before executing to avoid inconsistency in Visual Studio Code.
  • Regularly refresh the blob explorer view to verify changes applied to the storage.

These steps will help you effectively manage your data in Azure Blob Storage - keep learning and adding functionality to your projects!

Contributions 9

Questions 1

Sort by:

Want to see more contributions, questions and answers from the community?

Para hacerlo en la versi贸n 12 de Azure.Storage.Blob se deber谩 de hacer de la siguiente manera:

using Microsoft.Extensions.Configuration;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;

internal class Program
{
    private static async Task Main(string[] args)
    {
        var builder = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("appsettings.json");

        var config = builder.Build();

        string getConnString = config["ConnectionStrings"];

        string containerName = "myplatzistorage" + Guid.NewGuid().ToString();
        BlobServiceClient blobServiceClient = new BlobServiceClient(getConnString);
        BlobContainerClient containerClient = await blobServiceClient.CreateBlobContainerAsync(containerName, PublicAccessType.Blob);
        await containerClient.CreateIfNotExistsAsync();
    }
}

Paquete agregado:

  • Microsoft.Azure.Storage.Blob
    dotnet add package Microsoft.Azure.Storage.Blob --version 11.1.0
Archivo "Program.cs", funciona "dotnet build" y "dotnet run". Crea Containers en Azure. ![](https://static.platzi.com/media/user_upload/image-c7553acf-8f42-4776-81f6-d77021a5298f.jpg) ```js using System; using System.IO; using Microsoft.Azure; using Microsoft.Azure.Storage; using Microsoft.Azure.Storage.Blob; using Microsoft.Extensions.Configuration; //using Microsoft.Extensions.Configuration.FileExtensions; using Microsoft.Extensions.Configuration.Json; namespace BlobConsole { //0 references class Program { // 0 references static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json"); IConfiguration config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", true, true) .Build(); string getConnString = config["connectionstring"]; Console.WriteLine(getConnString); CloudStorageAccount cuentaAlmacenamiento = CloudStorageAccount.Parse(config["connectionstring"]); CloudBlobClient clienteBlob = cuentaAlmacenamiento.CreateCloudBlobClient(); CloudBlobContainer contenedor = clienteBlob.GetContainerReference("contenedorplatzi02"); contenedor.CreateIfNotExists(); contenedor.SetPermissions(new BlobContainerPermissions{PublicAccess = BlobContainerPublicAccessType.Blob}); } } } ```
He subido el ejemplo completo en este repositorio: [azure-container-examples/create-azure-container-registry at master 路 notyel/azure-container-examples (github.com)](https://github.com/notyel/azure-container-examples/tree/master/create-azure-container-registry)

ese paquete de azure.Storega.Blob tambien existe para otros lenguajes como nodeJS?

Que buena clase !

muy buena la clase

La cadena es especifica para cada uno de los proyectos, asi mismo puedes cifrarla al integrarla a tu proyecto para que quede aun mas seguro.