This Howto will explain how you can directly upload a video to HW and convert it from your website.
First, you need to enable the external upload capability from your account page (developer tab). Activating this option will give you an upload key to put in your upload form.
Upload form
You have two ways to upload a video: normal upload or ajax upload with progression.
Normal upload
In a page (upload.html for example), put this HTML form:
<form action="http://heywatch.com/upload" enctype="multipart/form-data" method="post" > <input type="hidden" value="YOUR_UPLOAD_KEY" name="key" /> <input type="hidden" value="http://yoursite.com/upload_success.php" name="redirect_if_success" /> <input type="hidden" value="http://yoursite.com/upload_error.php" name="redirect_if_error" /> <input type="hidden" value="20" name="your_site_user_id" /> <input type="hidden" value="1540" name="post_id" /> <p><input id="data" name="data" type="file" /></p> <p><input name="commit" type="submit" value="Upload" /></p> </form>That’s it!
Ajax upload
DISABLED
For those who already integrated the ajax upload, you will always have size=0 and received=0.
If you want progress bar, you can use a flash uploader like SWFUpload .
Form parameters
In the sample codes, we can see some hidden fields:
- key: your upload key (necessary to authenticate your account)
- redirect_if_success: redirect your user after a successful upload (optional)
- redirect_if_error: redirect your user after a failed upload. Will have the error code in parameter (optional)
- your_site_user_id: this is a custom field, custom fields are unlimited. This is important if you want to track your users’ videos or whatever.
- post_id: another custom field
Get notified
To get notified when an upload is finished, you must enable the ping after transfer in your account (developer tab). This address will receive all the info about the new uploaded video, and all the custom fields you’ve put in your upload form.
Here is an example:
{"upload_id"=>"UPLOAD_ID", "your_site_user_id"=>"20", "post_id"=> "1540", "video_id"=>"74885"}
If you’ve set the automatic encode and the ping_url_after_encode, the job will be automatically created and you’ll receive all the custom fields in the ping address.
Example:
{
"upload_id"=>"UPLOAD_ID",
"your_site_user_id"=>"20",
"post_id"=> "1540",
"encoded_video_id"=>"74885",
"filename"=>"HeyWatch_-_myvideo.flv",
"link"=>"http://heywatch.com/encoded_video/74885.bin"
}
So, without any efforts, you’ll be able to have your encoded video associated with your own objects (user_id, post_id).
If you don’t set the automatic encode, you need to create the job manually after getting the ping after transfer (custom fields included).