File Upload

My Cloud Home APIs allow users to upload various types of file content. You can choose one of the three upload options based on your requirements and the different conditions like device type, network strength, data throughput, etc.

Upload file content while creating file

This is a simple mode to upload file content. The following example creates a file along with file metadata and file content.

  POST /sdk/v2/files HTTP/1.1  Host: Endpoint-URL  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJS  Content-Type: multipart/related;boundary=foo  --foo  {     "name":"sample.txt",     "size":"20",     "parentID":"JK_F3685T",     "mimeType":"text/plain"  }  --foo  sample file content.  --foo--

Upload file content separately

File content can be uploaded separately using PUT /v2/files/{file-id}/content API. You may choose this mode when the file is small enough to upload in one single HTTP session, and re-upload again if the network connection fails.

  PUT /sdk/v2/files/{file-id}/content HTTP/1.1  Host: Endpoint-URL  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOi  Content-Type: application/x-www-form-urlencoded  file content goes here.

Upload file content in chunks (Resumable Upload)

Use this mode of upload when the file size is large. Resumable upload gives the flexibility of resuming an upload after a network failure. In this mode of upload, you would upload file content in chunks, and when one of the chunks failed to upload, it will resume uploading only from that chunk. You don't have to restart large file uploads from the beginning. This feature is particularly important when you are building apps for mobile devices. Resumable upload has the following three steps: Create a resumable file, Upload the file content in chunks and Mark resumable upload as finished.

Step 1: Create the resumable file

My Cloud Home will create a temporary location for the resumable file. This temporary file will not be visible to normal file operations. For example, file browsing.

  POST /sdk/v2/files/resumable HTTP/1.1  Host: Endpoint-URL  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSAhOo8sdxcalNiCFAcQ  Content-Type: multipart/related;boundary=foo  --foo  {    "name": "golang",    "parentID": "root"  }  --foo--

Step 2: Upload the file content in chunks

This action will be executed in loops until the whole file content is uploaded. File content will be saved in the resumable file in a temporary location.

  PUT /sdk/v2/files/{file-id}/resumable/content HTTP/1.1  Host: Endpoint-URL  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzIA24q1QaonJvQr5LQC8Fnivmr6VzlNiCFAcQ  Content-Type: application/x-www-form-urlencoded  this is the resumable upload content

Step 3: Mark the resumable upload as finished

When the whole file content is successfully uploaded, the application can mark the resumable upload as 'done.' Once the resumable upload is marked as 'done,' My Cloud Home will move the resumable file from the temporary location to the original location. The file will then be visible to all other file operations.

  PUT /sdk/v2/files/{file-id}/resumable/content?done=true HTTP/1.1  Host: Endpoint-URL  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1ai72Uy09tzh1x7jZNtnsh4omP8sdxcalNiCFAcQ  Content-Type: application/x-www-form-urlencoded