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.

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

报告相同问题?

悬赏问题

  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 已知隐函数其中一个变量的,求另外一个变量
  • ¥15 echarts图表制作
  • ¥15 halcon根据玻璃面板纹路取区域
  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究