Uploading files to Azure Blob Storage in PHP

Niels Vermaut
1 min readFeb 10, 2022

--

I recently started working in an environment where we had to work with Azure as our Cloud provider.

Everything so far hasn’t been different from other cloud providers. Some stuff works great, some stuff was clearly not a priority.

However, I was a bit annoyed when I realised that the documentation for the Azure Blob Storage upload was kind of cryptic and the samples where incorrect for PHP.

Object storage is one of the building blocks of modern Cloud deployment and I expected a bit better from Microsoft on this front.

For those people that are struggling with this: you are supposed to do this in your code:

use MicrosoftAzure\Storage\Blob\Models\Block;...$blobRestProxy = BlobRestProxy::createBlobService($connectionString);$uniqueIdentifier = Uuid::uuid4(); //generate a unique identifier$blockId = base64_encode(urlencode($uniqueIdentifier));// To the upload, as kind-off documented in the code sample.
$result = $blobRestProxy->createBlobBlock(
'my-container-name',
'test.json',
$blockId,
json_encode(["test" => "OK"])
);
// Commit the code block you just uploaded.$blobRestProxy->commitBlobBlocks(
$this->azureBlobStoragePilesContainerName,
$path,
[new Block($blockId, 'Uncommitted')]
);

--

--