I use this Python code to upload to PageBlob by manually chunking the file. It works. I translated that logic to C#. I am wondering is there a simpler solution built into Azure SKD? less hacky solution.
byte[] bytes = (encoding ?? Encoding.UTF8).GetBytes(content);
int fileSize = bytes.Length;
int blockSize = fileSize;
int boundary = blockSize % 512;
if (boundary != 0)
{
byte[] padding = Enumerable.Repeat((byte)0x0, 512 - boundary).ToArray();
bytes = bytes.Concat(padding).ToArray();
blockSize = blockSize + 512 - boundary;
}
// Allocate pages
cloudPageBlob.Create(
blockSize,
accessCondition,
options,
operationContext);
var CHUNK_MAX_SIZE = 4 * 1024 * 1024;
var count = (int)Math.Ceiling(1.0 * bytes.Length / CHUNK_MAX_SIZE);
int remaining = bytes.Length;
for (var i = 0; i < count; i++)
{
int chunkSize = Math.Min(CHUNK_MAX_SIZE, remaining);
cloudPageBlob.UploadFromByteArray(
bytes,
i,
chunkSize,
accessCondition,
options,
operationContext);
remaining -= chunkSize;
}