Skip to main content
added 23 characters in body
Source Link
Kunal Valecha
  • 444
  • 1
  • 4
  • 12

Once You have the file stream, you can use the below code to upload file to blob storage.

string azureConnString = "YourAzureStorageConnStringName";
    CloudBlobClient blobClient;
    CloudStorageAccount storageAccount;
    CloudBlobContainer container;
    CloudBlockBlob blockBlob;
    public bool AddFileToBlob(System.IO.Stream stream, string fileName, string containerName)
    {
        byte[] bytesarr =  AuditHelper.GetByteFromStream(stream); //Convert the stream to byte array

        using (MemoryStream memoryStrem = new MemoryStream(bytesarr))
        {

            // Retrieve storage account from connection string.
            storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting(azureConnString));

            // Create the blob client.
            blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            container = blobClient.GetContainerReference(containerName);
            container.CreateIfNotExists();

            // Retrieve reference to a blob named "myblob".
            blockBlob = container.GetBlockBlobReference(fileName);
            if (!blockBlob.Exists())
                blockBlob.UploadFromStream(memoryStrem);

           
            return true;
        }
    }

Once You have the file stream, you can use the below code to upload file to blob storage.

string azureConnString = "YourAzureStorageConnStringName";
    CloudBlobClient blobClient;
    CloudStorageAccount storageAccount;
    CloudBlobContainer container;
    CloudBlockBlob blockBlob;
    public bool AddFileToBlob(System.IO.Stream stream, string fileName, string containerName)
    {
        byte[] bytesarr =  AuditHelper.GetByteFromStream(stream);

        using (MemoryStream memoryStrem = new MemoryStream(bytesarr))
        {

            // Retrieve storage account from connection string.
            storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting(azureConnString));

            // Create the blob client.
            blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            container = blobClient.GetContainerReference(containerName);
            container.CreateIfNotExists();

            // Retrieve reference to a blob named "myblob".
            blockBlob = container.GetBlockBlobReference(fileName);
            if (!blockBlob.Exists())
                blockBlob.UploadFromStream(memoryStrem);

           
            return true;
        }
    }

Once You have the file stream, you can use the below code to upload file to blob storage.

string azureConnString = "YourAzureStorageConnStringName";
    CloudBlobClient blobClient;
    CloudStorageAccount storageAccount;
    CloudBlobContainer container;
    CloudBlockBlob blockBlob;
    public bool AddFileToBlob(System.IO.Stream stream, string fileName, string containerName)
    {
        byte[] bytesarr =  GetByteFromStream(stream); //Convert the stream to byte array

        using (MemoryStream memoryStrem = new MemoryStream(bytesarr))
        {

            // Retrieve storage account from connection string.
            storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting(azureConnString));

            // Create the blob client.
            blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            container = blobClient.GetContainerReference(containerName);
            container.CreateIfNotExists();

            // Retrieve reference to a blob named "myblob".
            blockBlob = container.GetBlockBlobReference(fileName);
            if (!blockBlob.Exists())
                blockBlob.UploadFromStream(memoryStrem);

           
            return true;
        }
    }
Source Link
Kunal Valecha
  • 444
  • 1
  • 4
  • 12

Once You have the file stream, you can use the below code to upload file to blob storage.

string azureConnString = "YourAzureStorageConnStringName";
    CloudBlobClient blobClient;
    CloudStorageAccount storageAccount;
    CloudBlobContainer container;
    CloudBlockBlob blockBlob;
    public bool AddFileToBlob(System.IO.Stream stream, string fileName, string containerName)
    {
        byte[] bytesarr =  AuditHelper.GetByteFromStream(stream);

        using (MemoryStream memoryStrem = new MemoryStream(bytesarr))
        {

            // Retrieve storage account from connection string.
            storageAccount = CloudStorageAccount.Parse(
            CloudConfigurationManager.GetSetting(azureConnString));

            // Create the blob client.
            blobClient = storageAccount.CreateCloudBlobClient();

            // Retrieve reference to a previously created container.
            container = blobClient.GetContainerReference(containerName);
            container.CreateIfNotExists();

            // Retrieve reference to a blob named "myblob".
            blockBlob = container.GetBlockBlobReference(fileName);
            if (!blockBlob.Exists())
                blockBlob.UploadFromStream(memoryStrem);

           
            return true;
        }
    }