zoukankan      html  css  js  c++  java
  • 通过 PHP 连接China Azure Blob 存储

    问题说明

    Azure Blob 存储是一种将非结构化数据作为对象/Blob存储在云中的服务。Blob存储可以存储任何类型的文本或二进制数据,例如文档、媒体文件或应用程序安装程序。Blob存储也称为对象存储。本指南将演示如何使用 Azure Blob 服务执行常见方案。示例是用 PHP编写的并使用了 Azure SDK for PHP。

    参考资料

    Code Sample

    <?php
    require_once 'vendorautoload.php';
    
    use MicrosoftAzureStorageCommonServicesBuilder;
    use MicrosoftAzureStorageBlobModelsCreateContainerOptions;
    use MicrosoftAzureStorageBlobModelsPublicAccessType;
    use MicrosoftAzureStorageCommonServiceException;
    
    // Create blob REST proxy.
    $connectionString = 'BlobEndpoint=http://<storage account name>.blob.core.chinacloudapi.cn/;QueueEndpoint=http://<storage account name>.queue.core.chinacloudapi.cn/;TableEndpoint=http://<storage account name>.table.core.chinacloudapi.cn/;AccountName=yunewstoragetest;AccountKey=<storage account key>';
    
    $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
    
    $createContainerOptions = new CreateContainerOptions();
    
    $createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS);
    
    // Set container metadata.
    $createContainerOptions->addMetaData("key1", "value1");
    $createContainerOptions->addMetaData("key2", "value2");
    
    try {
    	// Create container.
    	$blobRestProxy->createContainer("mycontainer", $createContainerOptions);
    }
    catch(ServiceException $e){
    	$code = $e->getCode();
    	$error_message = $e->getMessage();
    	echo $code.": ".$error_message."<br />";
    }
    
    echo "create container success!";
    ?>
    
    

    说明

    • 示例主要介绍如何设置连接字符串连接到中国版的Azure Storage;
    • 关于开发工具推荐使用Wamp+EclipsePHP,配置参考链接
  • 相关阅读:
    生成客户端信任的证书文件
    postgresql Streaming Replication监控与注意事项
    采用pacemaker+corosync实现postgresql双机热备、高可用方案
    51nod1305(简单逻辑)
    51nod1091(贪心)
    51nod1009(1的数目)
    51nod1102(数塔)
    51nod1459(带权值的dijkstra)
    51nod1265(判断四个点是否共面)
    51node1264(判断线段相交)
  • 原文地址:https://www.cnblogs.com/taro/p/6613343.html
Copyright © 2011-2022 走看看