我得到“失败:代码:403值:此请求无权执行此操作。详细信息(如果有):AuthorizationFailure此请求无权执行此操作。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>