Accessing Azure storage with a shared key in php

caiofior

Claudio Fior

Posted on June 28, 2024

Accessing Azure storage with a shared key in php

The new CTO like azure, so I had to access to azure storage blob and table from a php project.

The microsoft offical libraries are deprecated, so I made a the project caiofior/azure_storage using guzzle to access at this resources with a shared key.

$azureTable = new \Ftc\driver\AzureStorageTable(
    AZURE_STORAGE_ACCOUNT_TABLE_NAME,
    AZURE_STORAGE_ACCOUNT_TABLE_BASEURL,
    AZURE_STORAGE_ACCOUNT_TABLE_TOKENSAS
);

try {
    $tokenNata = $azureTable->get('file','%24filter='.urlencode('PartitionKey eq \''.$token.'\''));
} catch (\Exception $e) {
    die("Token errato !");
}
Enter fullscreen mode Exit fullscreen mode

Example of sorage table access

    $azureBlob = new \Ftc\driver\AzureStorageBlob(
        AZURE_STORAGE_ACCOUNT_FILE_NAME,
        AZURE_STORAGE_ACCOUNT_FILE_BASEURL,
        AZURE_STORAGE_ACCOUNT_FILE_TOKENSAS
    );

   $azureBlob->put(
        'file',
        $_FILES['uploadFile']['name'],
        $_FILES['uploadFile']['type'],
        $_FILES['uploadFile']['size'],
        fopen($_FILES['uploadFile']['tmp_name'],'r')
   );
Enter fullscreen mode Exit fullscreen mode

Example of file uploading

How to generate a sherd key in azure

How to generate a shared key

πŸ’– πŸ’ͺ πŸ™… 🚩
caiofior
Claudio Fior

Posted on June 28, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related