dongshiliao7990 2016-06-13 08:24
浏览 35
已采纳

Softlayer PHP Client中的Chunked文件上传

I need to upload large files to Softlayer Object Storage. How can I do this using PHP Client for Object Storage?

  • 写回答

1条回答 默认 最新

  • dongmi4734 2016-06-13 13:35
    关注

    Here a php example to upload files using SoftLayer Object Storage PHP Client:

    <?php
    require_once ('lib/ObjectStorage/Util.php');
    
    class ObjectStorageSL{
    
        var $objectStorage;
        public function __construct($host, $username, $password, $options) {
    
            $this -> objectStorage = new ObjectStorage($host, $username, $password, $options);
    
        }
    
        /**
         * This method shows token and url from an object storage
         * @var $objectStorage - Object Storage connection
         */
        function displayTokenUrl() {
            print("Token: " . $this -> objectStorage -> getAuthenticationData() -> authToken . "
    ");
            print("Url: " . $this -> objectStorage -> getAuthenticationData() -> objectStorageUrl);
        }
    
        /**
         * This method uploads a file located in your local machine
         * @var $objectStorage - Object Storage connection
         * @var $containerName - The container's name where you want to upload the object
         * @var $objectName - The object's name that you wish to assign for the file uploaded
         * @var $path - The path where the file is located
         */
        function uploadFile($containerName, $objectName, $path) {
            try {
                $result = $this -> objectStorage -> with($containerName . "/" . $objectName) -> setLocalFile($path) -> create();
                print("
    ".$result -> getUrl());
                print("
    The file has been uploaded");
            } catch(Exception $e) {
                echo "
    Error: " . $e -> getMessage();
            }
        }
    }
    
    
    /**
     * Declare Object Storage parameters
     */
    $host = 'https://mil01.objectstorage.softlayer.net/auth/v1.0/';
    // Declare your username and password for Object Storage connection
    $username = 'set me';
    $password = 'set me';
    $options = array('adapter' => ObjectStorage_Http_Client::SOCKET, 'timeout' => 10);
    
    /**
     * Create Object Storage Connection
     */
    $objectStorage = new ObjectStorageSL($host, $username, $password, $options);
    
    /**
     * Display Token and Url
     */
    $objectStorage -> displayTokenUrl();
    $path = "C:\Project\task.xml";
    $objectStorage -> uploadFile("rcvTest", "task1.xml", $path);
    

    I didn't test it with files bigger than 10 MB, but it should work, let me know if you have troubles or any question

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 c语言写的8051单片机存储器mt29的模块程序
  • ¥60 求直线方程 使平面上n个点在直线同侧并且距离总和最小
  • ¥50 java算法,给定试题的难度数量(简单,普通,困难),和试题类型数量(单选,多选,判断),以及题库中各种类型的题有多少道,求能否随机抽题。
  • ¥50 rk3588板端推理
  • ¥250 opencv怎么去掉 数字0中间的斜杠。
  • ¥15 这种情况的伯德图和奈奎斯特曲线怎么分析?
  • ¥250 paddleocr带斜线的0很容易识别成9
  • ¥15 电子档案元素采集(tiff及PDF扫描图片)
  • ¥15 flink-sql-connector-rabbitmq使用
  • ¥15 zynq7015,PCIE读写延时偏大