Upload HTML Canvas image to Azure Blob storage

Forums HTMLUpload HTML Canvas image to Azure Blob storage
Staff asked 2 years ago

Hi,

I’m attempting to upload a signature to Azure Blob Storage in Canvas.toDataURL() format. The issue I’m having is that the image I’m receiving does not fit the criteria set out by Azure.

Can somebody advise me on how to change it into the necessary form?

 

var img = canvas.toDataURL('image/jpeg', 0.9).split(',')[1];

in controller

byte[] bytes = Convert.FromBase64String(image);

   CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AzureString);

   CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

   CloudBlobContainer container = blobClient.GetContainerReference("img");

   string ImageFileName = RandomString(5) + ".jpg";

   CloudBlockBlob imgBlockBlob = container.GetBlockBlobReference(ImageFileName);

   using (MemoryStream ms = new MemoryStream(bytes))
   {
       imgBlockBlob.UploadFromStream(ms);
   }

 

Prince Dhameliya replied 2 years ago

Answers (1)

Add Answer
Prince Dhameliya Marked As Accepted
Staff answered 2 years ago
var img = canvas.toDataURL('image/jpeg', 0.9).split(',')[1];

in controller

byte[] bytes = Convert.FromBase64String(image);
   CloudStorageAccount storageAccount = CloudStorageAccount.Parse(AzureString);
   CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
   CloudBlobContainer container = blobClient.GetContainerReference("img");
   string ImageFileName = RandomString(5) + ".jpg";
   CloudBlockBlob imgBlockBlob = container.GetBlockBlobReference(ImageFileName);
   using (MemoryStream ms = new MemoryStream(bytes))
   {
       imgBlockBlob.UploadFromStream(ms);
   }

 

Subscribe

Select Categories