File/Folder Creation

Contents

You can create file and folder using the same API but with a different MIME type. You can either create only the file object and update the file content later or create the file object along with its content.

Folder Creation

In the My Cloud Home API, the special mimeType application/x.wd.dir identifies that the given request is to create a folder. You can create a new folder by inserting this mimetype and giving a folder name. The response will display the newly created folder ID /sdk/v2/files/{folder-id} in the Location header. For example Location:/sdk/v2/files/b-eEeXmv5K4R55L-fK_lIL866iuN07gvBzZzQUkf.


  POST /sdk/v2/files HTTP/1.1
  Host: Endpoint-URL
  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJS
  Content-Type: multipart/related;boundary=foo
  --foo

  {
    "name": "testfolder",
    "parentID": "root",
    "mimeType":"application/x.wd.dir"
  }
  --foo--

My Cloud Home API requires Content-Type to be “multipart/related” for all multipart requests. You can use the alias 'root' to refer to the root folder. The string representation of a multipart/related payload will look like ''\r\n--foo\r\n\r\n' + (json_payload) + '\r\n--foo--''.

File Creation

File creation uses the same API as the folder creation but without any folder specific MIME type. Apps can send file metadata like creation-time, modified-time, mimeType, etc. in the file creation request.


  POST /sdk/v2/files HTTP/1.1
  Host: Endpoint-URL
  Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJS
  Content-Type: multipart/related;boundary=foo
  --foo

  {
    "name": "hello.txt",
    "parentID": "root"
  }
  --foo--

The following example creates a file along with its metadata and 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--

APIs

Have question about this section?