Uploading an Object Body

The basic steps for uploading an object body are as follows:

  1. Initialize an upload.
  2. Upload an object body.
  3. Commit or cancel the upload.

Initializing an upload

First, you need to initialize an upload. The following example initializes an upload of an object body for a KiiObject in a bucket in a group scope.

curl -v -X POST \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  -H "Content-Type: application/vnd.kii.StartObjectBodyUploadRequest+json" \
  -H "Accept: application/vnd.kii.StartObjectBodyUploadResponse+json" \
  "https://api-jp.kii.com/api/apps/{APP_ID}/groups/{GROUP_ID}/buckets/{BUCKET_ID}/objects/{OBJECT_ID}/body/uploads" \
  -d '{ }'

Kii Cloud returns an upload ID as in the example below.

< 200
< Content-Type: application/vnd.kii.StartObjectBodyUploadResponse+json
{
  "uploadID" : {UPLOAD_ID}
}

Use this upload ID when actually uploading an object body in the next section.

Uploading an object body

Suppose that you upload an mp4 file of 1.5 MB by calling the API twice. The next example uploads the first 1 MB of this file.

curl -v -X PUT \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  -H "Content-Type: video/mp4" \
  -H "Content-Range: bytes=0-1048575/1572864" \
  -H "Accept: application/json, application/*+json" \
  "https://api-jp.kii.com/api/apps/{APP_ID}/groups/{GROUP_ID}/buckets/{BUCKET_ID}/objects/{OBJECT_ID}/body/uploads/{UPLOAD_ID}/data" \
  -d '***THE_FIRST_1_MB_OF_THE_BINARY_DATA***'

Make sure to set the correct byte range and the total file size in the "Content-Range" header. Also, make sure to set the proper value in the "Content-Type" header (the value will be returned when you later download the object body).

Kii Cloud returns a 204 response if the upload succeeds.

The remaining data can be uploaded as follows:

curl -v -X PUT \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  -H "Content-Type: video/mp4" \
  -H "Content-Range: bytes=1048576-1572863/1572864" \
  -H "Accept: application/json, application/*+json" \
  "https://api-jp.kii.com/api/apps/{APP_ID}/groups/{GROUP_ID}/buckets/{BUCKET_ID}/objects/{OBJECT_ID}/body/uploads/{UPLOAD_ID}/data" \
  -d '***THE_REMAINING_BINARY_DATA***'

If the upload succeeds, Kii Cloud will again return a 204 response.

Committing or canceling an upload

After an upload succeeds, you need to commit or cancel the upload.

Committing an upload

The following example shows how to commit an upload.

curl -v -X POST \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  "https://api-jp.kii.com/api/apps/{APP_ID}/groups/{GROUP_ID}/buckets/{BUCKET_ID}/objects/{OBJECT_ID}/body/uploads/{UPLOAD_ID}/status/committed" \
  -d ""

Kii Cloud returns a 204 response if the commit is successful.

Canceling an upload

The following example shows how to cancel an upload.

curl -v -X POST \
  -H "Authorization: Bearer {ACCESS_TOKEN}" \
  "https://api-jp.kii.com/api/apps/{APP_ID}/groups/{GROUP_ID}/buckets/{BUCKET_ID}/objects/{OBJECT_ID}/body/uploads/{UPLOAD_ID}/status/cancelled" \
  -d ""

Kii Cloud returns a 204 response if the cancellation is successful.