So I came onto this piece of code that was trying to replicate a BlockBlob from one place to another.
1 | destinationBlob.Properties.ContentType = sourceBlob.Properties.ContentType; |
The problem
First, it will download the whole block locally to re-upload it.
That is pretty awesome but what if your file is 500Mb? Yeah. It’s completely loaded into memory and your process memory usage will explode. Worse, if your process is 32bits, you might actually run into OutOfMemoryException
sooner rather than later.
The solution
Azure already provides a way to copy data from one blob to another. All this code was replaced by this single line of code.
1 | newBlob.StartCopy(oldBlob); |
If you don’t know how to do something in Azure, looking at the API or asking around might just save you a few hours of troubleshooting.