I want to download an Azure blob into stream and then convert stream to image for resizing and then upload new image to Azure blob with a new name. now I can resize the image and upload the stream but I can't upload the stream with new name to Azure.
This is my code:
Stream stream = blockBlob.OpenRead();
Image newImage;
Bitmap image = new Bitmap(stream);
newImage = new Bitmap(image, 20, 20);
var ms = new MemoryStream();
newImage.Save(ms, ImageFormat.Png);
ms.Position = 0;
blockBlob.UploadFromStream(ms);
This is actually pretty simple. What you could need to do is create an instance of CloudBlockBlob
with new blob name and upload the content there. Assuming you wish to upload the new file in the same container, this is what you could do:
Stream stream = blockBlob.OpenRead();
Image newImage;
Bitmap image = new Bitmap(stream);
newImage = new Bitmap(image, 20, 20);
var ms = new MemoryStream();
newImage.Save(ms, ImageFormat.Png);
ms.Position = 0;
var newBlob = blockBlob.Container.GetBlockBlobReference("new-blob-name.png");
newBlob.UploadFromStream(ms);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With