doumuyu0837 2013-07-11 18:06
浏览 70
已采纳

使用PHP curl存储具有开放堆栈API文件存储的对象

I am using php curl to call open stack's api to store a object. My curl call looks like this

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

dummyfile.pdf is the file name i want the stored file to be called.

    $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);

The response keeps returning a 408 Request Timeout

Has anyone figured this out. Also am i specifying the file location to be uploaded correctly using the content-location header or is there another way to do.

  • 写回答

1条回答 默认 最新

  • dongmin4052 2013-07-11 23:57
    关注

    For Anyone whos having the same issue i solved the problem the following way:

     $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");    
    

    This seemed to resolve it and upload the file from the url to object storage server.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?