簡體   English   中英

使用cloudmanic-storage將文件上傳到雲

[英]Uploading file to the cloud using cloudmanic-storage

我正在嘗試使用codeigniter和cloudmanic-storage庫將文件從服務器上傳到CDN。 創建/列出容器的功能有效,但向容器添加文件的功能無效。

我不知道它有什么問題或如何解決此問題,因此,如果有人遇到了這個問題,分享一些知識將是很棒的:)

$container = 'cm-storage-' . time();
    echo '<h1>Create test container.</h1>';
    $this->storage->create_container($container, 'private');
    echo "New container: <b>$container</b><br /><br />";
    echo '<hr />';
            $file = "_data/articlepics/big_".$config['file_name'];
    $this->storage->upload_file($container, $file, 'test01.jpg');

我確定要上傳的文件存在,當我使用示例控制器進行嘗試時,問題仍然存在。 它只是出於某種原因不想將文件上傳到CDN。

Codeigniter Ver.2.0.2來自github的最新cloudmanic-storage

似乎尚未定義類型,並且guess函數無法猜測文件是什么。

我所做的是在控制器中上載/調整文件大小時整理文件,然后(在我知道擴展名之后)只需將文件類型添加到rackspace_rc_driver.php

function upload_file($cont, $path, $name, $type = NULL, $acl = 'private', $metadata = array())
    {       

$ type =“ image / jpeg”;

$my_container = $this->_conn->get_container($cont);

        // move local file to server        
        $my_object = $my_container->create_object($name);

        // If we pass in a type we don't try to guess the type.
        if(! is_null($type))
        {
            $my_object->content_type = $type;
        }
        //echo $path;die();
        $my_object->load_from_filename($path);

        return ($my_object->container->cdn_enabled) ? $my_object->container->cdn_uri . '/' . $my_object->name : $my_object->name;
    }

希望這對其他人有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM