作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 azure php SDK,并且拥有从应用程序获得的 SAS 签名,现在如何使用 SAS(共享访问签名)将文件上传到 blob。
最佳答案
如果您有 SAS token ,并且它具有对 Azure 存储帐户中的 blob 的写入权限,则您可以利用 SAS token 将文件直接上传到 Azure 存储,而无需适用于 PHP 的 Azure 存储 SDK。
我假设您拥有带签名的正确 SAS 查询字符串,该字符串应类似于:?sv=2015-04-05&ss=bt&srt=sco&sp=w&st=2016-09-01T01%3A54%3A00Z&se=2016-09-02T01%3A54%3A00Z&sig=AQ%2F1yL8bt0AQzoYwtQmTUR6UKkJPC4PXg%2B xysdlkMoE%3D
然后,您利用 cUrl
创建到 Azure 存储的 REST API 请求来上传文件,
$sas= '?sv=2015-04-05&ss=bt&srt=sco&sp=rwl&st=2016-09-01T01%3A54%3A00Z&se=2016-09-02T01%3A54%3A00Z&sig=To%2BITizcZWTgr4I6o9BI%2Bdv34CBkuhV5%2BSEQXnaJr%2B0%3D';
$endpoint = 'https://<storage_account>.blob.core.windows.net';
$container = 'test';
$blob = 'test.png';
$url = $endpoint.'/'.$container.'/'.$blob.$sas;
$uploadfile ="test.PNG";
$content = file_get_contents($uploadfile);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('x-ms-blob-type: BlockBlob','Content-Length: ' . strlen($content)));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS,$content);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
您可以引用https://msdn.microsoft.com/en-us/library/azure/dd179451.aspx有关用于将 blob 放入 Azure 存储的 REST API 的更多详细信息。
关于php - 如何使用 PHP 的共享访问签名在 azure 中上传 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39241302/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!