1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Binary File Data

Discussion in 'PHP & Perl' started by Mutikasa, Dec 13, 2011.

  1. Mutikasa

    Mutikasa Power Member

    Joined:
    May 23, 2011
    Messages:
    574
    Likes Received:
    207
    This is not really specific PHP, but since I want to do this with PHP it goes here.
    anyway, this is how POST request for uploading Youtube looks like:

    POST /feeds/api/users/default/uploads HTTP/1.1
    Host: uploads.gdata.youtube.com
    Authorization: AuthSub token="<authentication_token>"
    GData-Version: 2
    X-GData-Key: key=<developer_key>
    Slug: <video_filename>
    Content-Type: multipart/related; boundary="<boundary_string>"
    Content-Length: <content_length>
    Connection: close

    --<boundary_string>
    Content-Type: application/atom+xml; charset=UTF-8

    API_XML_request
    --<boundary_string>
    Content-Type: <video_content_type>
    Content-Transfer-Encoding: binary

    <Binary File Data>
    --<boundary_string>


    Now, what i don't understand is <Binary File Data>.
    This is what Google says:
    Binary File Data - This value contains the binary code for the video file that is being uploaded.

    how do I get that binary code?
     
  2. ijof9

    ijof9 Power Member

    Joined:
    Mar 27, 2010
    Messages:
    536
    Likes Received:
    594
    Occupation:
    CTO
    Location:
    Western Europe
    Read about multipart form data. But you shouldn't try to split the file into chunks yourself. You should use cURL to handle the uploads.
     
    • Thanks Thanks x 1
  3. xpwizard

    xpwizard Junior Member

    Joined:
    Nov 6, 2010
    Messages:
    198
    Likes Received:
    122
    For the binary file data, just specify the file and curl will handle it for you. Make sure to use the "@" sign before the location though:
    Code:
    $file = "/var/www/videos/sample.mp4";
    $data = array('name' => 'file', 'file' => "@$file");
     
    • Thanks Thanks x 1
    Last edited: Dec 13, 2011
  4. ijof9

    ijof9 Power Member

    Joined:
    Mar 27, 2010
    Messages:
    536
    Likes Received:
    594
    Occupation:
    CTO
    Location:
    Western Europe
    It's "@{$file}" for interoperability (IIS/CGI, CLI, etc) and it should be "@" . $file (for syntax highlighting).
     
    • Thanks Thanks x 1