Search code examples
phpcurlwistia

Wistia : Uploading file using curl and php


I am trying to upload an mp4 file using curl and php to Wistia video hosting. But i am constantly getting 500 server error in response even though all the parameters seem to be fine.

Here is the code where i do a curl call:

$ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,);
    curl_setopt($ch,CURLOPT_POST, true);
    curl_setopt($ch,CURLOPT_POSTFIELDS,$params);

    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch,CURLOPT_HEADER,true);
    //curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: multipart/form-data'));

    $result = curl_exec($ch);

    $responseInfo = curl_getinfo($ch);

    echo '<pre>'; print_r($responseInfo); exit;

The $params array has two indexes, file and api_password .

And i set the $params array as :

$params = array('file'=>'@'.realpath('./wistiatest.mp4'),'api_password'=>'xxx');

And it responds with following error(500):

Array
(
[url] => https://upload.wistia.com/
[content_type] => text/html;charset=utf-8
[http_code] => 500
[header_size] => 717
[request_size] => 186
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 1.484906
[namelookup_time] => 0.004125
[connect_time] => 0.251725
[pretransfer_time] => 0.781186
[size_upload] => 416
[size_download] => 30
[speed_download] => 20
[speed_upload] => 280
[download_content_length] => 30
[upload_content_length] => 416
[starttransfer_time] => 1.034712
[redirect_time] => 0
[redirect_url] => 
[primary_ip] => 162.209.59.225
[certinfo] => Array
    (
    )

[primary_port] => 443
[local_ip] => 10.28.81.19
[local_port] => 47150
)

I have also tried setting file type and filename parameters. But to no avail.

$param = array('file'=>'@'.$file.' ;type=application/octet-stream'.' ;filename=wistiatest.mp4','api_password'=>'xxx');

Also, even though i pass in array params to CURLOPT_POSTFIELDS, i have tried setting explicitly the Content-Type header to multipart/form-data but that didn't work either.


Solution

  • Even though i have solved the issue by using CURLFile but i still want to know why it does not work without it. Here is where i found a useful example for CURLFile.