繁体   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