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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵