Reputation: 1637
How to create a blob in a container in Microsoft Azure using PHP. Followed the steps in this link
But still facing some issues. The PHP code is not getting executed. How to push a file or directory into existing blob?
<?php
require_once 'vendor/autoload.php';
use MicrosoftAzure\Storage\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\ServiceException;
$connectionString = "DefaultEndpointsProtocol=https://sen123.blob.core.windows.net/srs123/sen123;[email protected];AccountKey= ";
// Create blob REST proxy.
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$content = fopen("D:\home\site\wwwroot\blobfile.txt", "r");
$blob_name = "sen123";
try {
//Upload blob
$blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content);
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/library/azure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
?>
Error message: This page isn’t working sen.azurewebsites.net is currently unable to handle this request. HTTP ERROR 500
Upvotes: 1
Views: 89
Reputation: 9940
Your connection string is incorrect.
The value of DefaultEndpointsProtocol should be https
or http
, not the URL of your blob file.
For AccountName and AccountKey you can copy these values from the Azure portal:
On the Windows platform, you need to change the file path to:
$content = fopen("D:\\home\\site\\wwwroot\\blobfile.txt", "r");
Upvotes: 2