从 Azure 存储 blob 下载文件的简单 PHP cURL 方法
Simple PHP cURL method for downloading file from Azure storage blob
我正在将文件从本地服务器上传到 Azure 存储 - 使用简单 PHP cURL 函数的 blob 容器。我从下面获取代码 url .
有人可以告诉我可以从 Azure 存储下载文件的任何 link 或代码 - 没有任何 SDK and/or 多个 files/libraries 的 blob。应该是上传功能吧
提前致谢!
这是sample that I referred to. It's very detailed and may help you understand using cURL to request API, like Get Blob API。
要求:
GET https://myaccount.blob.core.windows.net/mycontainer/myblob
x-ms-date: Mon, 24 Apr 2021 06:34:09 GMT
x-ms-version: 2014-02-14
Authorization: SharedKey myaccount:<signature_str>
你可以参考这个
<?php
$storageAccount = '';
$containerName = '';
$blobName = '';
$account_key = '';
$date = gmdate('D, d M Y H:i:s \G\M\T');
$version = "2019-12-12";
$stringtosign = "GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:". $date . "\nx-ms-version:".$version."\n/".$storageAccount."/".$containerName."/".$blobName;
$signature = 'SharedKey'.' '.$storageAccount.':'.base64_encode(hash_hmac('sha256', $stringtosign, base64_decode($account_key), true));
echo "\n\n" . $signature;
$header = array (
"x-ms-date: " . $date,
"x-ms-version: " . $version,
"Authorization: " . $signature
);
$url="https://$storageAccount.blob.core.windows.net/$containerName/$blobName";
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header);
curl_exec ( $ch );
$result = curl_exec($ch);
echo "\n\n" . $result;
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
file_put_contents('D://demo//downloaded.txt', $result); // save the string to a file
curl_close($ch);
我正在将文件从本地服务器上传到 Azure 存储 - 使用简单 PHP cURL 函数的 blob 容器。我从下面获取代码 url .
有人可以告诉我可以从 Azure 存储下载文件的任何 link 或代码 - 没有任何 SDK and/or 多个 files/libraries 的 blob。应该是上传功能吧
提前致谢!
这是sample that I referred to. It's very detailed and may help you understand using cURL to request API, like Get Blob API。
要求:
GET https://myaccount.blob.core.windows.net/mycontainer/myblob
x-ms-date: Mon, 24 Apr 2021 06:34:09 GMT
x-ms-version: 2014-02-14
Authorization: SharedKey myaccount:<signature_str>
你可以参考这个
<?php
$storageAccount = '';
$containerName = '';
$blobName = '';
$account_key = '';
$date = gmdate('D, d M Y H:i:s \G\M\T');
$version = "2019-12-12";
$stringtosign = "GET\n\n\n\n\n\n\n\n\n\n\n\nx-ms-date:". $date . "\nx-ms-version:".$version."\n/".$storageAccount."/".$containerName."/".$blobName;
$signature = 'SharedKey'.' '.$storageAccount.':'.base64_encode(hash_hmac('sha256', $stringtosign, base64_decode($account_key), true));
echo "\n\n" . $signature;
$header = array (
"x-ms-date: " . $date,
"x-ms-version: " . $version,
"Authorization: " . $signature
);
$url="https://$storageAccount.blob.core.windows.net/$containerName/$blobName";
$ch = curl_init ();
curl_setopt ( $ch, CURLOPT_URL, $url );
curl_setopt ( $ch, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt ( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header);
curl_exec ( $ch );
$result = curl_exec($ch);
echo "\n\n" . $result;
if(curl_errno($ch)){
throw new Exception(curl_error($ch));
}
file_put_contents('D://demo//downloaded.txt', $result); // save the string to a file
curl_close($ch);