gpt4 book ai didi

php - 错误 404 : azure storage create a new Block

转载 作者:行者123 更新时间:2023-12-03 04:33:30 25 4
gpt4 key购买 nike

我正在尝试在 Azure 存储上上传大型特定图像文件(从 1 MB 到 5 GB)。

对于最大 2MB 的小文件,其他文件没有问题,我收到“您正在查找的资源已被删除、名称已更改或暂时不可用。”回答。

因此,我尝试使用以下代码将文件分成几个 block :

require_once 'vendor/autoload.php';

use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
use WindowsAzure\Blob\Models\CreateContainerOptions;
use WindowsAzure\Blob\Models\PublicAccessType;
use WindowsAzure\Blob\Models\Block;
use WindowsAzure\Blob\Models\BlobBlockType;

define('CHUNK_SIZE', 1024*1024); //Block Size = 1MB
$connectionString = "DefaultEndpointsProtocol=....";
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);

$uploadfile =$_FILES['fileToUpload']['tmp_name'];
$content = fopen($uploadfile, "r");
$blob_name = $_FILES['fileToUpload']['name'];
$container_name = "natives";

try{
$counter = 1;
$blockIds = array();
while(!feof($content)){

$blockId = str_pad($counter, 6, "0", STR_PAD_LEFT);
$block = new Block();
$block -> setBlockId(base64_encode($blockId));
$block -> setType("Uncommitted");
array_push($blockIds, $block);

$data = fread($content, CHUNK_SIZE);

echo " \ n";
echo "Read ". strlen($data) . "of data from file <br />";
echo "Uploading block #:". $blockId . "into blob storage. Please wait. <br />";
$blobRestProxy -> createBlobBlock($container_name, $blob_name, base64_encode($blockIds), $data);

echo "Uploaded block: ".$blockId . "into blob storage. <br />";

$counter = $counter + 1;

}
echo "Now committing block list. Please wait. <br />";
$blobRestProxy -> commitBlobBlocks($container_name, $blob_name, $blockIds);
echo "Blob created successfully. <br />";
}
catch(Exception $e){
echo "Error <br />";
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
echo "Files : ".$_FILES['fileToUpload']['name']."<br />";
echo "content " . $content."<br />";
}
fclose($content);

使用 Debug模式,问题来自

$block = new Block();

尽管如此,我包含了“Block”类,所以我不明白这个问题,并且我不知道如何获得有关此错误的更多信息。我在开发者页面 (POST) 上只有一个白页和一个错误 404。

最佳答案

所以我尝试了你的代码,但没有得到你所得到的 404 错误。不过我确实发现你的代码有问题。本质上,您需要更改以下代码行:

$blobRestProxy -> createBlobBlock($container_name, $blob_name, base64_encode($blockIds), $data);

$blobRestProxy -> createBlobBlock($container_name, $blob_name, base64_encode($blockId), $data);

完成此操作后,我就可以在我的存储帐户中正确上传文件。

关于php - 错误 404 : azure storage create a new Block,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32221140/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com