作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 Azure PHP SDK 将大块 blob 分块上传到 Azure 存储,但我无法在任何地方找到如何执行此操作的示例,那么如何使用 Azure PHP SDK 执行此操作?
最佳答案
这是一个工作示例。我使用了上面链接中提到的相同的两个函数。
<?php
require_once 'WindowsAzure/WindowsAzure.php';
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
use WindowsAzure\Blob\Models\Block;
use WindowsAzure\Blob\Models\BlobBlockType;
define('CHUNK_SIZE', 1024*1024);//Block Size = 1 MB
try {
$connectionString = "UseDevelopmentStorage=true";
$instance = ServicesBuilder::getInstance();
$blobRestProxy = $instance -> createBlobService($connectionString);
$containerName = "mycontainer";
$blobName = "DSC01166.jpg";
$content = fopen("d:\DSC01166.jpg", "rb");
$index = 0;
$continue = True;
$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);
echo $blockId . " | " . base64_encode($blockId) . " | " . count($blockIds);
echo " \n ";
echo " -----------------------------------------";
$data=fread($content, CHUNK_SIZE);
echo "Read " . strlen($data) . " of data from file";
echo " \n ";
echo " -----------------------------------------";
echo " \n ";
echo " -----------------------------------------";
echo "Uploading block #: " . $blockId + " into blob storage. Please wait.";
echo " -----------------------------------------";
echo " \n ";
$blobRestProxy -> createBlobBlock($containerName, $blobName, base64_encode($blockId), $data);
echo "Uploaded block: " . $blockId . " into blob storage. Please wait";
echo " \n ";
echo " -----------------------------------------";
echo " \n ";
$counter = $counter + 1;
}
fclose($content);
echo "Now committing block list. Please wait.";
echo " -----------------------------------------";
echo " \n ";
echo "hello";
$blobRestProxy -> commitBlobBlocks($containerName, $blobName, $blockIds);
echo " -----------------------------------------";
echo " \n ";
echo "Blob created successfully.";
}
catch(Exception $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/en-us/library/windowsazure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
?>
希望这有帮助。
关于php - 如何使用 Azure PHP SDK 通过分块来上传大块 blob?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17612325/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!