代码:403 值:此请求无权执行此操作. 详细信息(如果有):授权失败



我得到">失败:代码:403值:此请求无权执行此操作。详细信息(如果有(:授权失败此请求无权执行此操作。请求 ID:a433a473-e01e-005a-2fa7-30f90a000000 时间:2020-05-23T02:12:36.6988696Z。错误。请参阅下面的代码。

require_once 'vendor/autoload.php';
use MicrosoftAzureStorageBlobBlobRestProxy;
use MicrosoftAzureStorageBlobBlobSharedAccessSignatureHelper;
use MicrosoftAzureStorageBlobModelsCreateBlockBlobOptions;
use MicrosoftAzureStorageCommonServicesBuilder;
use MicrosoftAzureStorageCommonExceptionsServiceException;
use MicrosoftAzureStorageCommonExceptionsInvalidArgumentTypeException;
use MicrosoftAzureStorageCommonInternalResources;
use MicrosoftAzureStorageCommonInternalStorageServiceSettings;
use MicrosoftAzureStorageCommonModelsRange;
use MicrosoftAzureStorageCommonModelsLogging;
use MicrosoftAzureStorageCommonModelsMetrics;
use MicrosoftAzureStorageCommonModelsRetentionPolicy;
use MicrosoftAzureStorageCommonModelsServiceProperties;
use MicrosoftAzureStorageBlobModelsBlock;
use MicrosoftAzureStorageBlobModelsBlockList;
use MicrosoftAzureStorageBlobModelsBlobBlockType;
$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标头的值格式不正确。 详细信息(如果有(: 无效标头值其中一个 HTTP 标头的值格式不正确。请求 Id: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>

我正在从文件上传发送空数据.. 现在我将数据存储在托管服务器中并上传到 blob。

require_once 'vendor/autoload.php';
use MicrosoftAzureStorageBlobBlobRestProxy;
use MicrosoftAzureStorageBlobBlobSharedAccessSignatureHelper;
use MicrosoftAzureStorageBlobModelsCreateBlockBlobOptions;
use MicrosoftAzureStorageCommonServicesBuilder;
use MicrosoftAzureStorageCommonExceptionsServiceException;
use MicrosoftAzureStorageCommonExceptionsInvalidArgumentTypeException;
use MicrosoftAzureStorageCommonInternalResources;
use MicrosoftAzureStorageCommonInternalStorageServiceSettings;
use MicrosoftAzureStorageCommonModelsRange;
use MicrosoftAzureStorageCommonModelsLogging;
use MicrosoftAzureStorageCommonModelsMetrics;
use MicrosoftAzureStorageCommonModelsRetentionPolicy;
use MicrosoftAzureStorageCommonModelsServiceProperties;
use MicrosoftAzureStorageBlobModelsBlock;
use MicrosoftAzureStorageBlobModelsBlockList;
use MicrosoftAzureStorageBlobModelsBlobBlockType;

$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>

相关内容

最新更新