0

I am used cURL in PHP for uploading a video to Wistia. Everything works fine in my local server. But in dev server , the video is not uploading. Using the var_dump(curl_getinfo($ch)), I can see the content_type is different from local to dev server. I am confused about it.Can any one help me to resolve this problem.

Here is my code:

public function video_upload($filePath)
{         
    $data = array(
        'api_password'  => '0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX5',
        'file'          => '@'.$filePath,
    );

    $url = 'https://upload.wistia.com';    
    $ch  = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL            => $url,
        CURLOPT_POST           => true,
        CURLOPT_POSTFIELDS     => $data,
        CURLOPT_HEADER         => false,
        CURLOPT_RETURNTRANSFER => true,
    ));
    curl_setopt($ch, CURLINFO_HEADER_OUT, true);
    $response = curl_exec($ch);

    var_dump(curl_getinfo($ch));
    var_dump(curl_errno($ch));
    curl_close($ch);

    return $response;
}

Response received in my local server:

array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(30) "application/json;charset=utf-8"**
    ["http_code"]=> int(200)
    ["header_size"]=> int(688)
    ["request_size"]=> int(189)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(17.850026)
    ["namelookup_time"]=> float(0.252903)
    ["connect_time"]=> float(0.253271)
    ["pretransfer_time"]=> float(1.903306)
    ["size_upload"]=> float(279250)
    ["size_download"]=> float(417)
    ["speed_download"]=> float(23)
    ["speed_upload"]=> float(15644)
    ["download_content_length"]=> float(417)
    ["upload_content_length"]=> float(279250)
    ["starttransfer_time"]=> float(2.173591)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(13) "162.209.95.19"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(13) "192.168.1.157"
    ["local_port"]=> int(54999)
    ["request_header"]=> string(189) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 279250 Expect: 100-continue Content-Type: multipart/form-data; boundary=------------------------370a5719d6336ecc "
} int(0)

Response received in my dev server :

array(27) {
    ["url"]=> string(26) "https://upload.wistia.com/"
    **["content_type"]=> string(23) "text/html;charset=utf-8"**
    ["http_code"]=> int(500)
    ["header_size"]=> int(718)
    ["request_size"]=> int(186)
    ["filetime"]=> int(-1)
    ["ssl_verify_result"]=> int(0)
    ["redirect_count"]=> int(0)
    ["total_time"]=> float(0.437061)
    ["namelookup_time"]=> float(0.004766)
    ["connect_time"]=> float(0.023656)
    ["pretransfer_time"]=> float(0.194844)
    ["size_upload"]=> float(319)
    ["size_download"]=> float(30)
    ["speed_download"]=> float(68)
    ["speed_upload"]=> float(729)
    ["download_content_length"]=> float(30)
    ["upload_content_length"]=> float(319)
    ["starttransfer_time"]=> float(0.216544)
    ["redirect_time"]=> float(0)
    ["redirect_url"]=> string(0) ""
    ["primary_ip"]=> string(15) "162.242.168.223"
    ["certinfo"]=> array(0) { }
    ["primary_port"]=> int(443)
    ["local_ip"]=> string(14) "224.178.240.48"
    ["local_port"]=> int(55164)
    ["request_header"]=> string(186) "POST / HTTP/1.1 Host: upload.wistia.com Accept: */* Content-Length: 319 Expect: 100-continue Content-Type: multipart/form-data; boundary=----------------------------d45c07c28860 "
} int(0) 
phaberest
  • 3,140
  • 3
  • 32
  • 40
trial a
  • 21
  • 2

3 Answers3

0

It's hard to say why it is not working, but the response you get from the server includes a 500 http status code, which indicates that something is wrong on the server.

It is possible that there is something wrong on your end, but without more information from the server, it's really hard to tell what is going wrong. In general, 500 responses from the server indicates a server (wistia) error, not a client (you) error.

You might want to send the information to wistia to get more details.

Daniel Andre
  • 303
  • 1
  • 7
0

I bet you're doing a different POST request altogether, do like

$verbosefileh=tmpfile();
$verbosefile=stream_get_meta_data($verbosefileh)['uri'];
curl_setopt_array($ch,array(
CURLOPT_CERTINFO=>true,
CURLOPT_VERBOSE=>true,
CURLOPT_STDERR=>$verbosefileh
));
curl_exec($ch);
$postrequest=file_get_contents($verbosefile);

then study the post request closely, what's the difference between the request sent by the 2 servers? i bet there is something.. unless you're blocked out of IP ban

edit: a common gotcha, on some installations curl has a default useragent, and on some installations, curl doesn't. (like in debian 6, its something like "curl/7.21.3 (x86_64-unknown-linux-gnu) libcurl/7.21.3 OpenSSL/1.0.0c zlib/1.2.5", while in debian 8, there IS no default string.. or was it the other way around?), and many websites will block requests that doesn't contain a useragent. to ensure you have a useragent, you can use curl_setopt($ch,CURLOPT_USERAGENT,'curl php');

hanshenrik
  • 19,904
  • 4
  • 43
  • 89
0

You are getting a 500 error from the server in the second response. That's why it is not json.

phaberest
  • 3,140
  • 3
  • 32
  • 40