开发者

Updating Modifying File To Rackspace Cloud

How can I update files to rackspace api? I've tried several things like the code below, and it only works if I uplo开发者_如何学Pythonad the image twice. Is there anyway of doing this?

public function updateRackSpaceFile($file_name, $file_location, $container_name='photos'){
        $auth=self::getAuthorization();

        $conn = new \CF_Connection($auth);
        $container_object = $conn->get_container($container_name);
        $object=$container_object -> get_object($file_name);
        $object ->load_from_filename($file_location);
    }


I don't think you need to do a get on the object. Simply create a new object and upload. It will replace the object with the same name.

    $fname = basename('image.jpg');
    $md5 = md5_file($fname);
    $container = $conn->get_container('my_container');
    $o2 = $container->create_object($fname);
    $o2->content_type = "image/jpeg";
    $o2->set_etag($md5);
    $result = $o2->load_from_filename($fname);
    assert('!is_null($result)');
    assert('$o2->getETag() == $md5');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜