Uploading simple Blobs to Azure Storage
public static class BlobStorageHelper
{
public static void FileUpload(string filePath)
{
var credentials = new StorageCredentials("<<Azure Storage Name>>",
"<<Primary Key>>");
var client = new CloudBlobClient(new Uri("<<Azure Blob Storage Path - Full URL>>), credentials);
// Retrieve a reference to a container. (You need to create one using the mangement portal, or call container.CreateIfNotExists())
var container = client.GetContainerReference("<<Blob Name>>");
// Retrieve reference to a blob named "myfile.gif".
var blockBlob = container.GetBlockBlobReference("<<File Name>>");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"<<Full File Path with file name and extension>>"))
{
blockBlob.UploadFromStream(fileStream);
}
}
}
public static class BlobStorageHelper
{
public static void FileUpload(string filePath)
{
var credentials = new StorageCredentials("<<Azure Storage Name>>",
"<<Primary Key>>");
var client = new CloudBlobClient(new Uri("<<Azure Blob Storage Path - Full URL>>), credentials);
// Retrieve a reference to a container. (You need to create one using the mangement portal, or call container.CreateIfNotExists())
var container = client.GetContainerReference("<<Blob Name>>");
// Retrieve reference to a blob named "myfile.gif".
var blockBlob = container.GetBlockBlobReference("<<File Name>>");
// Create or overwrite the "myblob" blob with contents from a local file.
using (var fileStream = System.IO.File.OpenRead(@"<<Full File Path with file name and extension>>"))
{
blockBlob.UploadFromStream(fileStream);
}
}
}
No comments:
Post a Comment