【发布时间】:2020-09-09 23:56:11
【问题描述】:
我得到“Fail: Code: 403 Value: This request is not authorized to perform this operation. details (if any): AuthorizationFailureThis request is not authorized to perform this operation. RequestId:a433a473-e01e-005a- 2fa7-30f90a000000 时间:2020-05-23T02:12:36.6988696Z.”错误。请在下面查看我的代码。
require_once 'vendor/autoload.php';
use MicrosoftAzure\Storage\Blob\BlobRestProxy;
use MicrosoftAzure\Storage\Blob\BlobSharedAccessSignatureHelper;
use MicrosoftAzure\Storage\Blob\Models\CreateBlockBlobOptions;
use MicrosoftAzure\Storage\Common\ServicesBuilder;
use MicrosoftAzure\Storage\Common\Exceptions\ServiceException;
use MicrosoftAzure\Storage\Common\Exceptions\InvalidArgumentTypeException;
use MicrosoftAzure\Storage\Common\Internal\Resources;
use MicrosoftAzure\Storage\Common\Internal\StorageServiceSettings;
use MicrosoftAzure\Storage\Common\Models\Range;
use MicrosoftAzure\Storage\Common\Models\Logging;
use MicrosoftAzure\Storage\Common\Models\Metrics;
use MicrosoftAzure\Storage\Common\Models\RetentionPolicy;
use MicrosoftAzure\Storage\Common\Models\ServiceProperties;
use MicrosoftAzure\Storage\Blob\Models\Block;
use MicrosoftAzure\Storage\Blob\Models\BlockList;
use MicrosoftAzure\Storage\Blob\Models\BlobBlockType;
$blobendpoint = "<Blob service SAS URL>"
$connectionString = "BlobEndpoint=".$blobendpoint.";SharedAccessSignature=sv=2019-10-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2020-06-06T08:58:51Z&st=2020-05-23T00:58:51Z&sip=52.175.254.10&spr=https,http&sig=<Signature>";
$containerName = "samples";
$blobRestProxy = BlobRestProxy::createBlobService($connectionString);
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
$file_name = $_FILES["resFile"]["name"];
$blob_name = basename($file_name);
$block_list = new BlockList();
define('CHUNK_SIZE', 4 * 1024 * 1024);
try {
$fptr = fopen($file_name, "rb");
$index = 1;
while (!feof($fptr)) {
$block_id = base64_encode(str_pad($index, 6, "0", STR_PAD_LEFT));
$block_list->addUncommittedEntry($block_id);
$data = fread($fptr, CHUNK_SIZE);
$blobRestProxy->createBlobBlock($containerName, $blob_name, $block_id, $data);
++$index;
}
echo "Index :".$index;
$blobRestProxy->commitBlobBlocks($containerName, $blob_name, $block_list);
} catch (ServiceException $e) {
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
}
?>
<form action="fileuploadblock.php" method="POST" enctype="multipart/form-data">
<input type="file" class="btn btn-default" name="resFile" id="resFile" value="" />
<input type="submit" class="btn btn-default" name = "share "value="Submit" data-inline="true"/>
</form>
编辑: 从 SAS 中删除 IP 后,我得到不同的错误:HTTP 标头之一的值格式不正确。详细信息(如果有):InvalidHeaderValue HTTP 标头之一的值格式不正确。 RequestId:cdb1b3c1-b01e-0078-29fd-303c15000000 时间:2020-05-23T12:28:57.6060563ZContent-Length0.
这是新的 $connectionString
BlobEndpoint=https://<account>.blob.core.windows.net/;SharedAccessSignature=sv=2019-10-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2020-05-23T20:17:23Z&st=2020-05-23T12:17:23Z&spr=https,http&sig=<SignatureValue>
【问题讨论】:
-
您的
$blobendpoint是什么样的?是不是像https://account.blob.core.windows.net? -
@GauravMantri-AIS,是的,它是:https://
.blob.core.windows.net -
我注意到您在 SAS 令牌 (52.175.254.10) 中应用了 IP 地址限制。请确保运行此代码的服务器具有此 IP 地址。
-
是的,我正在使用这个服务器(52.175.254.10)来运行代码。
-
我能想到的另一个原因是您的存储帐户位于防火墙后面。
标签: php azure-blob-storage azure-sas