编码: 403值。此请求未被授权执行此操作,详情(如有)。AuthorizationFailure

问题描述 投票:1回答:1

我得到"失败。代码: 403值: 此请求未被授权执行此操作,详情(如有)。AuthorizationFailure此请求未被授权执行此操作。RequestId:a433a473-e01-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后,我得到不同的错误。The value for one of the HTTP headers is not in the correct format.详情(如果有的话)。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>
php azure-storage-blobs azure-sas
1个回答
0
投票

我从文件上传发送的是空数据......现在我把数据存储在托管服务器上,然后上传到blob....

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;


 $connectionString = "BlobEndpoint=https://<account>.blob.core.windows.net/;SharedAccessSignature=sv=2019-10-10&ss=bfqt&srt=sco&sp=rwdlacupx&se=2021-05-26T17:39:04Z&st=2020-05-27T09:39:04Z&spr=https,http&sig=<Signature>";
$containerName = "samples";
$blobRestProxy = BlobRestProxy::createBlobService($connectionString);

/*****************Upload file to hosting ********/
function uploadFile($fieldName, $fileType)
{
    $flg = 0;
    $MaxID = "";
    $ext = "";
    $uploadfile = "";
    if (isset($fieldName) AND $fieldName['name'] != '')
    {
        $flg = 1;
        $allowed_filetypes = $fileType;
        $max_filesize = 40548576;
        $filename = $fieldName['name'];
        $ext = substr($filename, strpos($filename, '.'), strlen($filename) - 1);
        if($ext==".xlsx")
            $ext=".xls";
        if (!in_array($ext, $allowed_filetypes))
            echo "<h1>The file you attempted to upload is not allowed...</h1>";
        else if (filesize($fieldName['tmp_name']) > $max_filesize)
            echo "<h1>The file you attempted to upload is too large...</h1>";
        else 
        {
            $uploadfile =  $filename;//$MaxID . $ext;
            if (move_uploaded_file($fieldName['tmp_name'], $uploadfile) == FALSE)
            {
                echo "<h1>Error in Uploading File...</h1>";
                $MaxID = "";
            }
            else
                $MaxID = $filename;
            echo "file uploaded success!!";
        }
    }
    return $MaxID;
}
/***************************************/   
if(isset($_POST['share']))
{
    if($_FILES['resFile']['name']!="")
    {
      $file_name=uploadFile($_FILES['resFile'],array(".xls",".xlsx",".csv"));
    }
    if ($file_name != '')
    {
    $blob_name = basename($file_name);

$block_list = new BlockList();

define('CHUNK_SIZE', 1 * 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);
        //echo "Data :".$block_id;
        $blobRestProxy->createBlobBlock($containerName, $blob_name, $block_id, $data);
        //echo "ID :".$block_id;
        ++$index;
    }

    $blobRestProxy->commitBlobBlocks($containerName, $blob_name, $block_list);
} catch (ServiceException $e) {
    $code = $e->getCode();
    $error_message = $e->getMessage();
    echo "Error Code :".$code."Error Message : ".$error_message."<br />";
}
}
else 
{
    echo " No file selected";
}
}   
?>
<html lang="en">
<head>
</head>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="upload_excel" 
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"/>
<!--<div id="res"></div>-->

</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</body>
</html>
© www.soinside.com 2019 - 2024. All rights reserved.