Chunked Upload
Updated: December 20, 2016
Process Flow
If a 500 or 409 error is returned, call the Query Uploaded Data interface. To stop the upload, call Cancel Upload.
Initialize Upload
POST /upload_init?org_client_id={org_client_id} HTTP/1.1
Host: {upload_server_domain}
x-gk-upload-filename: {filename}
x-gk-upload-pathhash: {file_unique_id}
x-gk-upload-filehash: {file_sha1_hash}
x-gk-upload-filesize: {file_size}
x-gk-token: {token}
HTTP Headers | Required | Description |
---|---|---|
x-gk-upload-filename | Yes | File name, URL-encoded according to RFC3986 |
x-gk-upload-pathhash | Yes | Unique file identifier, the hash returned from the Upload File interface |
x-gk-upload-filehash | Yes | SHA1 hash of the file content, 40 characters in lowercase |
x-gk-upload-filesize | Yes | Size of the file |
x-gk-token | No | User access_token , not required when using the Library File API |
URL Parameters | Required | Description |
---|---|---|
org_client_id | No | Library authorization ID, required when using the Library File API |
Successful Response
HTTP 200
{
"session": "upload session ID"
}
HTTP 202 Instant completion without needing further steps
Error Response
HTTP 400 Missing parameters
Upload Data Chunk
PUT /upload_part HTTP/1.1
Host: {upload_server_domain}
x-gk-upload-session: {session}
x-gk-upload-range: {range}
x-gk-upload-crc: {crc}
HTTP Headers | Required | Description |
---|---|---|
x-gk-upload-session | Yes | Upload session ID |
x-gk-upload-range | Yes | Position of the current chunk, e.g., 0-199 indicates bytes 0 through 199 |
x-gk-upload-crc | No | CRC checksum of the data chunk, a 32-bit unsigned integer |
HTTP Content
The file chunk data to be uploaded, with a maximum size of 10MB
Successful Response
HTTP 200 Chunk uploaded successfully
HTTP 202 Temporary file on server is complete, call Complete Upload next
Error Response
HTTP 401 Invalid session parameter
HTTP 400
- CRC parameter mismatch
{
"error_code": 40001,
"error_msg": "part crc mismatch:23857631 expect 12856363"
}
- Range parameter and chunk size mismatch
{
"error_code": 40002,
"error_msg": "part length error:2049 expect 2048"
}
HTTP 409 Chunk does not match the server's temporary file; the expect
field indicates the expected start position for the chunk
{
"error_code": 40900,
"error_msg": "range begin:0 expect:2048",
"expect": 2048
}
HTTP 410 Temporary file on the server is being operated on and cannot accept new chunks
HTTP 416 Invalid range parameter
HTTP 500 Server error, failed to write the chunk
Query Uploaded Data
POST /upload_req HTTP/1.1
Host: {upload_server_domain}
x-gk-upload-session: {session}
HTTP Headers | Required | Description |
---|---|---|
x-gk-upload-session | Yes | Upload session ID |
Successful Response
HTTP 200
Returns a numeric value, such as 2048
, indicating the number of bytes uploaded
Error Response
HTTP 500 Upload was not initialized
HTTP 401 Invalid session parameter
Complete Upload
POST /upload_finish HTTP/1.1
Host: {upload_server_domain}
x-gk-upload-session: {session}
HTTP Headers | Required | Description |
---|---|---|
x-gk-upload-session | Yes | Upload session ID |
Successful Response
HTTP 200 Success
HTTP 202 The upload request is being processed; retry after a delay
Error Response
HTTP 500 Upload was not initialized (re-initialize with Initialize Upload)
HTTP 401 Invalid session parameter
HTTP 409 Incomplete data; more chunks need to be uploaded (call Query Uploaded Data)
Cancel Upload
POST /upload_abort HTTP/1.1
Host: {upload_server_domain}
x-gk-upload-session: {session}
HTTP Headers | Required | Description |
---|---|---|
x-gk-upload-session | Yes | Upload session ID |
Successful Response
HTTP 200 Success
Error Response
HTTP 500 Upload was not initialized
HTTP 401 Invalid session parameter