DEV Community

Claudio Fior
Claudio Fior

Posted on

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay