使用PHP curl存储对象,并使用开放堆栈API文件存储


Using PHP curl to store object with open stack API file storage

我正在使用php-ccurl调用openstack的api来存储对象。我的卷曲呼叫看起来像这个

 $token = $this->getToken();       
 $url = 'http://myfilestorageurl.com/v1/AUTH_volume/container/dummyfile.pdf';    

dummyfile.pdf是我希望调用存储文件的文件名。

    $ch=curl_init();
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'X-Auth-Token:'.$token,
        'Content-Length: 5611',      //not sure if its required
        'X-HTTP-Method-Override: PUT',   //not sure if its required
        'Content-Location:/data/dummyfile.pdf'
    ));

    curl_setopt($ch, CURLOPT_URL, $url_call);
    curl_setopt($ch, CURLOPT_HEADER, TRUE);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");     
    $response = curl_exec($ch);

响应不断返回408请求超时

有人想明白了吗。此外,我是否使用内容位置标头指定要正确上传的文件位置,或者是否有其他方法。

对于任何有同样问题的人,我通过以下方式解决了问题:

 $url = 'http://myurltouploadfileto.com';
 $fp = fopen('http://urlToFileToUpload.com');
 $ch=curl_init();
 curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth-Token:sometoken'));
 curl_setopt($ch, CURLOPT_PUT, true);
 curl_setopt($ch, CURLOPT_INFILE, $fp);     //this was the main one that i was missing
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_HEADER, TRUE);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");    

这似乎解决了问题,并将文件从url上传到对象存储服务器。