本文介绍了从Azure存储Blob下载文件的简单PHP cURL方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用简单PHP cURL函数将文件从本地服务器上传到Azure存储-blob容器.我从url下面获取了代码.
I am uploading file from local server to Azure storage - blob container using Simple PHP cURL function. I taken code from below url .
https://stackoverflow.com/questions/41682393/simple-php-curl-file-upload-to-azure-storage-blob
有人可以告诉我可以从Azure存储下载文件的任何链接或代码吗?blob,没有任何SDK和/或多个文件/库.它应该像一个上传功能.
Can someone tell me any link or code which I can download file from Azure storage - blob without any SDK and/or multiple files/libraries. It should be like a upload function.
提前谢谢!
推荐答案
这是样本.它非常详细,可以帮助您了解使用cURL请求API,例如获取Blob API .
This is the 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存储Blob下载文件的简单PHP cURL方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!