0

我正在使用 php curl 调用开放堆栈的 api 来存储对象。我的 curl 电话看起来像这样

 $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 Request Timeout

有没有人弄清楚这一点。我也是使用 content-location 标头指定要正确上传的文件位置,还是有其他方法可以做。

4

1 回答 1

1

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

 $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 上传到对象存储服务器。

于 2013-07-11T23:57:14.950 回答