The steps description: 1. create: connect to upload API server, to get upload_token and upload_server_uri. 2. create_file: connect to uploading server (with the IP address which is resolved from the upload_server_uri returned by create call before. the following so called uploading server is corresponding to the server with this IP address), to create file uploading process with upload_token and file_md5 as parameters (also with some other parameters together). 3. new_slice: connect to uploading server, to get the first slice uploading point. 4. upload_slice: connect to uploading server, upload one slice of data, and get the next slice uploading point. 5. check: connect to uploading server, to check whether or not the file uploading process accomplished. the result is descripted as blow:
* status=1: the file is totally uploaded, and confirmed written to disk.
* status=2: the file is still in uploading, all of the slices upload task are dispatched to perform. See confirmed_percent in the return data.
* status=3: the file is still in uploading, all of the slices upload task are accomplished, but there is still some slices are not confirmed written to disk. See confirmed_percent in the return data.
* status=4: the file is still in uploading, and there are still slice upload tasks to distribute.
commit: connect to upload API server, call commit with upload_token and upload_server_ip as parameters to confirm the upload process is totally accomplished.
Broken Uploading Resuming
The steps description: 1. check: connect to uploading server (with the IP address which is resolved from the upload_server_uri returned by create call before) to check if the file uploading phase is accomplished. The states definition is:
* status=1: the file is totally uploaded, and confirmed written to disk.
* status=2: the file is still in uploading, all of the slices upload task are dispatched to perform. See confirmed_percent in the return data.
* status=3: the file is still in uploading, all of the slices upload task are accomplished, but there is still some slices are not confirmed written to disk. See confirmed_percent in the return data.
* status=4: the file is still in uploading, and there are still slice upload tasks to distribute.
uploading: 2 difference situations:
if check returned 4
new_slice
upload_slice
if check returned 2 or 3, wait a while (e.g. 60 seconds) and then call check again.
commit: connect to upload API server, call commit with the upload_token and server_uri as parameters to confirm the uploading process is totally accomplished. ## API Description
title: string, MUST provide. title of the video clip, which is limited to 2 to 50 english characters long, and MUST contains one letter at least.
tags: string, default is the client name string. tags of the video clip, comma (‘,’) seperated. limit: 2-6 Chinese characters or 2-12 English characters, and max up to 10 tags.
category: string, Optional. Specific category see schemas/video/category.
public_type: string, default is ‘all’.
‘all’: no limit to be access.
‘friend’: only accessable to friends.
‘password’: password protected.
copyright_type: string, default is ‘original’.
‘original’
‘reproduced ‘
watch_password: string, the plain text password string when public_type is ‘password_protected’. default is empty string (“”).
description: string, default is empty string (“”). 2000 characters limited at most.
file_md5: string, MUST provide.
file_name: string, MUST provide.
file_size: int, MUST provide. the file size in byte.
latitude: double. Optional.
longitude: double. Optional.
shoot_time: double, in seconds. Optional.
Return Value
error: object. Only returned when error occured. code: int.
type: string.
description: string.
upload_token: string, the upload process token to do folloing steps.
instant_upload_ok: string, “yes” or “no”. Indicate if Instant Uploading process is available.
upload_server_uri: string. Only returned when instant_upload_ok is “no”. The client SHOULD resolve the hostname to IP address and remember for following steps.
Error Codes
120010101 - Title cannot be empty
120010102 - Title cannot be more than 60 characters long (updated)
120010104 - Banned content in title
120010111 - Duplicated uploading by the same user
120010121 - Tags must not be empty
120010122 - More than 10 tags specified
120010123 - Sensitive words in tags
120010124 - Tag is less than 2 letters (updated)
120010125 - Tag is longer than 12 letters (updated)
The sub-process of file uploading is devided into several steps descripted below.
The uploading server is resolved by DNS server according to the location of the user, and the IP address of the server MUST be recorded locally by the client to connect to perform all of the following steps of uploading phase.http://gX.upload.youku.com/gupload should be replaced by http://214.54.36.57/gupload“214.54.36.57” is “gX.upload.youku.com” pinged from your local address.
create_file
Interface
POST http://gX.upload.youku.com/gupload/create_file < .. parameters .. >
Parameters
upload_token: string, MUST provide.
file_size: int, MUST provide. file size in bytes.
ext: string, MUST provide. the extension of the file name.
slice_length: int, the length of each slice to upload, in K-bytes. The max is 10240, and default is 2048.
status: int, the uploading status of the whole file.
1: the file is totally uploaded, and confirmed written to disk.
2: the file is still in uploading, all of the slices upload task are dispatched to perform. See confirmed_percent in the return data.
3: the file is still in uploading, all of the slices upload task are accomplished, but there is still some slices are not confirmed written to disk. See confirmed_percent in the return data.
4: the file is still in uploading, and there are still slice upload tasks to distribute.
transferred_percent: int, the server received data percentage. meaningful when status == 2.
confirmed_percent: int, the server received and confirmed to be written to disk data percentage. meaningful when status == 3.
empty_tasks: int, task that not dispatched. meaningful when status == 4.
finished: boolen, whether or not the file is totally uploaded.
upload_server_ip: string, used to call #commit or #cancel
upload_server_ip: string, default is empty string (“”). Returned by calling #check from uploading server. If it’sInstant Uploading, using empty string (“”).
Client Uploading
Uploading Flow
Uploading Flow Description
General Uploading
The steps description: 1. create: connect to upload API server, to get upload_token and upload_server_uri. 2. create_file: connect to uploading server (with the IP address which is resolved from the upload_server_uri returned by create call before. the following so called uploading server is corresponding to the server with this IP address), to create file uploading process with upload_token and file_md5 as parameters (also with some other parameters together). 3. new_slice: connect to uploading server, to get the first slice uploading point. 4. upload_slice: connect to uploading server, upload one slice of data, and get the next slice uploading point. 5. check: connect to uploading server, to check whether or not the file uploading process accomplished. the result is descripted as blow:
Broken Uploading Resuming
The steps description: 1. check: connect to uploading server (with the IP address which is resolved from the upload_server_uri returned by create call before) to check if the file uploading phase is accomplished. The states definition is:
Prepare Phase
login
login to get access_token (clients of normal level), upload videos to the account. clients of partner level get access_token
token_refresh
This token should be used to refresh the access token when the old access token expired, to avoid every day login.
POST https://openapi.youku.com/v2/oauth2/token
POST /v2/oauth2/token Host: openapi.youku.com
client_id=123 &client_secret=demo_secret &grant_type=refresh_token &refresh_token=4bda296b570a6bba6ff02944cf10d13f
200 OK { “access_token”:”11d0b7627154f0dd000e6084f3811598”, “expires_in”:”3600”, “refresh_token”:”4bda296b570a6bba6ff02944cf10d13f”, “token_type”: “bearer” }
show_basic
This API is used to get the video clip’s info, including its state..
GET https://openapi.youku.com/v2/videos/show_basic.json
GET /v2/videos/show_basic.json?client_id=123&video_id=XMjg1MTcyNDQ0 Host: openapi.youku.com —-
200 OK
{ “id”: “XMjg1MTcyNDQ0”, “title”: “demo user”, “link”: “http://v.youku.com/v_show/id_XMjg1MTcyNDQ0.htm”, “thumbnail”: “http://g4.ykimg.com/0100641F464E1FC”, “duration”: “910”, “category”: “original”, “state”: “normal”, “published”: “2011-07-15 09:00:42”, “description”: “demo description”, “player”: “http://player.youku.com/player.php/sid/XMjg1MTcyNDQ0/v.swf”, “public_type”: “all”, “copyright_type”: “original”, “user”: { “id”: 58921428, “name”: “demo user”, “link”: “http://u.youku.com/user_show/id_UMjM1Njg1NzEy.html” } }
Uploading Phase
create
GET https://api.youku.com/uploads/create.json
GET /v2/uploads/create.json? client_id=123 &access_token=demo_access_token &title=demo%20video &tags=demo &public_type=password_protected ©right_type=original &watch_password=demopassword &description=this%20is%20a%20demo &file_md5=00000000000000000000000000 &file_name=demo.avi &file_size=123456 &latitude=39.980572 &longitude=116.307289
Host: openapi.youku.com
201 Created
{ “upload_token”: “1a2b3c4d”, “instant_upload_ok”: “no”, “upload_server_uri”: “g01.upload.youku.com” }
upload
The sub-process of file uploading is devided into several steps descripted below.
The uploading server is resolved by DNS server according to the location of the user, and the IP address of the server MUST be recorded locally by the client to connect to perform all of the following steps of uploading phase.http://gX.upload.youku.com/gupload should be replaced by http://214.54.36.57/gupload“214.54.36.57” is “gX.upload.youku.com” pinged from your local address.
create_file
POST http://gX.upload.youku.com/gupload/create_file < .. parameters .. >
POST /gupload/create_file Host: g01.upload.youku.com upload_token=1a2b3c4d &file_size=87654321 &ext=avi &slice_length=2048
201 Created
{ }
new_slice
GET http://gX.upload.youku.com/gupload/new_slice
GET /gupload/new_slice?upload_token=1a2b3c4d Host: g01.upload.youku.com
201 Created
{ “slice_task_id”: 1328793281567, “offset”: 12358023, “length”: 12345, “transferred”: 12358023, “finished”: false }
upload_slice
POST http://gX.upload.youku.com/gupload/upload_slice?< .. parameters .. >
< .. BINARY DATA .. >
POST /gupload/upload_slice?upload_token=1a2b3c4d &slice_task_id=1328792850123 &offset=12345678 &length=12345 &crc=dfc6f27b Host: g01.upload.youku.com
< .. BINARY DATA .. >
201 Created
{ “slice_task_id”: 1328793281567, “offset”: 12358023, “length”: 12345, “transferred”: 12358023, “finished”: false }
check
Query the video uploading process state.
GET http://gX.upload.youku.com/gupload/check
GET http://gX.upload.youku.com/gupload/check?upload_token=1a2b3c4d Host: g01.upload.youku.com
200 OK
{ “status”: 4, “upload_server_ip”: “10.103.5.55”, “transferred_percent”: 0, “confirmed_percent”: 0, “empty_tasks”: 114, “finished”: false }
commit
POST https://api.youku.com/uploads/commit.json
POST /v2/uploads/commit.json Host: openapi.youku.com
client_id=123&access_token=demo_access_token&upload_token=1a2b3c4d&upload_server_ip=1.2.3.4
200 OK
{ “video_id”: “XMjg1MTcyNDQ0” }
cancel
Cancel current upload session, including slice uploading tasks.
GET https://openapi.youku.com/v2/uploads/cancel.json
GET /v2/uploads/cancel.json?client_id=123&access_token=demo_access_token Host: openapi.youku.com
200 OK
{ “upload_token”: “1a2b3c4d” }
spec
Get the uploading configuration specification.
GET https://openapi.youku.com/v2/schemas/upload/spec.json
GET /v2/schemas/upload/spec.json Host: openapi.youku.com
200 OK
{ “allowed_max_file_size”: 20480000, “allowed_extensions”: “wmv,avi,dat,asf” }
Error Definition