Send (Pass) FileUpload path to azure CloudBlobClient in ASP.Net

nauna
 
on Mar 23, 2021 03:06 AM
521 Views

Hello,

I follow the link and created arrange this code.

Upload Image to Azure Blob Storage using C# in ASP.Net

problem is how to pass fileupload path

string accountname = "amimageblob";
string accesskey = "24ssGQO/eCaMSS7E9VdIwFraydt8rhjYK0ZbbQhj2RCs6MXwgN/U7Kcbmmv5rtqOQ9jde1P4oFrUfUtQXldm/g==";
StorageCredentials creden = new StorageCredentials(accountname, accesskey);
CloudStorageAccount acc = new CloudStorageAccount(creden, useHttps: true);
CloudBlobClient client = acc.CreateCloudBlobClient();
CloudBlobContainer cont = client.GetContainerReference("mysample");
cont.CreateIfNotExists();
cont.SetPermissions(new BlobContainerPermissions
    {
        PublicAccess = BlobContainerPublicAccessType.Blob
    });
CloudBlockBlob cblob = cont.GetBlockBlobReference("Sampleblob.jpg");
using (Stream file = System.IO.File.OpenRead(@ "D:\amit\Nitin sir\Nitinpandit.jpg"))
{
    cblob.UploadFromStream(file);
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Mar 23, 2021 04:13 AM
nauna says:
using (Stream file = System.IO.File.OpenRead(@ "D:\amit\Nitin sir\Nitinpandit.jpg"))
 
{
 
    cblob.UploadFromStream(file);
 
}

Replace above with below code.

cblob.UploadFromStream(fuUpload.PostedFile.InputStream);