From f8fc7380943f838e08d11cbb67fb32b3f1e2dcc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Fejfar?= Date: Sun, 9 May 2021 21:08:37 +0200 Subject: [PATCH] Fix for files with sizes divisible with BLOCKSIZE https://twitter.com/tomasfejfar/status/1391468977424064519 If filesize is 8 * 1024 * 1024 this will generate 3 requests. The last one will be 0 bytes and fail with invalid content-length=0 header. --- storage/BlockBlobExample.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/storage/BlockBlobExample.php b/storage/BlockBlobExample.php index 90bf765..3f2947b 100644 --- a/storage/BlockBlobExample.php +++ b/storage/BlockBlobExample.php @@ -125,7 +125,7 @@ function createContainerIfNotExists($blobRestProxy) $counter = 1; $blockIds = array(); - while (!feof($handle)) + while ($data = fread($handle, BLOCKSIZE)) { $blockId = str_pad($counter, PADLENGTH, "0", STR_PAD_LEFT); echo "Processing block $blockId.\n"; @@ -135,8 +135,6 @@ function createContainerIfNotExists($blobRestProxy) $block->setType("Uncommitted"); array_push($blockIds, $block); - $data = fread($handle, BLOCKSIZE); - // Upload the block. $blobRestProxy->createBlobBlock(CONTAINERNAME, BLOCKBLOBNAME, base64_encode($blockId), $data); $counter++; @@ -167,4 +165,4 @@ function createContainerIfNotExists($blobRestProxy) echo "$code: $error_message"; } -?> \ No newline at end of file +?>