3

I am working on a Hootsuite script that needs to upload a file using cURL PUT request. On Hootsuite site, I found below example code but I am being able to convert below code in PHP script :

curl -X PUT -H 'Content-Type: video/mp4' \
         -H "Content-Length: 8036821" \
         -T "/Users/kenh/Downloads/amazing_race.mp4" \
         "https://hootsuite-video.s3.amazonaws.com/production/3563111_6923ef29-d2bd-4b2a-a6d2-11295411c988.mp4?AWSAccessKeyId=AKIAIHSDDN2I7V2FDJGA&Expires=1465846288&Signature=3xLFijSn02YIx6AOOjmri5Djkko%3D"

I tried below code but it is still not working :

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => "https://hootsuite-video.s3.amazonaws.com/production/3563111_6923ef29-d2bd-4b2a-a6d2-11295411c988.mp4?AWSAccessKeyId=AKIAIHSDDN2I7V2FDJGA&Expires=1465846288&Signature=3xLFijSn02YIx6AOOjmri5Djkko%3D",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "PUT",
            CURLOPT_POSTFIELDS => array('file' => '@' . realpath('/Users/kenh/Downloads/amazing_race.mp4')),
            CURLOPT_HTTPHEADER => array(
              'Content-Type: video/mp4',
              'Content-Length: 8036821'    
            )
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

So can anybody help me out by telling how to convert above code in PHP ? I'll be thankful.

Hyyan Abo Fakher
  • 3,497
  • 3
  • 21
  • 35
Ankit
  • 627
  • 1
  • 9
  • 22
  • What error do you get? Do you have valid ssl certificate on your server? – Navid Sep 13 '18 at 06:19
  • No, I am trying from localhost and receiving this error : cURL Error #:Operation timed out after 30015 milliseconds with 0 bytes received. – Ankit Sep 13 '18 at 06:26
  • Try to add these options `CURLOPT_SSL_VERIFYPEER => false, // Don't verify Client SSL Certificate` and `CURLOPT_SSL_VERIFYHOST => 2, // Don't verify Host SSl Certificate` – Navid Sep 13 '18 at 06:29
  • Tried above setting but again getting same error : cURL Error #:Operation timed out after 30015 milliseconds with 0 bytes received. – Ankit Sep 13 '18 at 06:56

1 Answers1

0

Try appending http_build_query on the CURLOPT_POSTFIELDS option, like below :

CURLOPT_POSTFIELDS => http_build_query( array( 'file' => '@' . realpath( '/Users/kenh/Downloads/amazing_race.mp4' ) ) ),

From what I know, the http_build_query is required on the post fields when using PUT method.

Hasta Dhana
  • 4,699
  • 7
  • 17
  • 26