Binary File Data

Mutikasa

Power Member
Joined
May 23, 2011
Messages
589
Reaction score
216
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?
 
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.
 
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");
 
Last edited:
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");

It's "@{$file}" for interoperability (IIS/CGI, CLI, etc) and it should be "@" . $file (for syntax highlighting).
 
Back
Top