Create a new file or folder

Contents

Create a new file or folder.

Endpoint URL: {network.internalDNSName or network.proxyURL} received in DeviceInformation

Request Syntax


POST /v2/files



Request Headers

Parameter Description Required
Authorization An access token with nas_read_write scope as well as a File Permission with value WriteFile or FileOwner for a parent.

Value of type: string
true
Content-Type Indicates the content type of the returned content. The value must be multipart/related.

Value of type: string
true


Request Query Parameters

Parameter Description Required
resolveNameConflict If the file with the same name already exists, resolve the conflicting name by appending a number.

Value of type: boolean

Default: false
false


Request Body

Parameter Description Required
Body part 1: cTime The file creation time.

Value of type: dateTime

Default: Current time
false
Body part 1: hidden Which OS the file is hidden on. Possible values mac, linux, windows or none.

Value of type: string

Default: none
false
Body part 1: mimeType The Media Type of the file. Use application/x.wd.dir for directories and folders.

Value of type: string

Default: Automatically detected or `application/octet-stream`
false
Body part 1: mimeTypes List of mimeTypes for all the contents if multiple contents are provided in Body part 2. If the first element is an empty string, it will be autodetected.

Value of type: array of strings

Default: Empty array
false
Body part 1: mTime The file modification time.

Value of type: dateTime

Default: Current time
false
Body part 1: name The name of the file.

Value of type: string

Default: Automatically generated
false
Body part 1: parentID The parent ID or the alias root.

Value of type: string

Default: root
false
Body part 2 The file contents. If there is a "multipart/related" content, each part will be stored as a separate content. The parts should match the mimeTypes array length.

Default: Zero bytes
false
Body part 3 The preview source contents (only JPEG accepted). Will be used to generate image previews.

Default: Zero bytes
false


201 Response

The normal case will be 201.

Response Headers

Parameter Description Required
ETag An eTag (entity tag) is an HTTP response header used to determine the change in file metadata and content in the My Cloud Home server.

Value of type: string
false
Location A relative URL to the created file's endpoint.

Value of type: string
false


401 Response

Valid token required.

404 Response

Device not found.

Example

Sample request to create a new regular file.

Request


POST /sdk/v2/files HTTP/1.1
Host: Endpoint-URL
Authorization: Bearer 25951a7e-ffae-4edb-abb2-5e57d4ffb759
Content-Type: multipart/related;boundary=foo
--foo

{
  "name": "newfile",
  "parentID": "root"
}
--foo

contents of file
--foo--

Response


HTTP/1.1 201 Created
Etag: "Ag"
Location: /sdk/v2/files/SCtt6sReL85MCZ-Ds-MrAVR67JkbpPqLKzqpyQnl
Vary: Origin
Date: Mon, 29 Aug 2016 19:18:19 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8


Example (Multiple Contents)

Sample request to create a new regular file with multiple contents.

Request


POST /sdk/v2/files HTTP/1.1
Host: Endpoint-URL
Authorization: Bearer 25951a7e-ffae-4edb-abb2-5e57d4ffb759
Content-Type: multipart/related;boundary=foo
--foo

{
  "name": "live_photo.heic",
  "parentID": "root",
  "mimeTypes": ["image/heic", "video/quicktime"]
}
--foo
Content-Type: multipart/related; boundary=bar

--bar

[content of live_photo.heic]
--bar

[content of live_photo.mov]
--bar--
--foo

[content of live_photo_preview.jpg]
--foo--

Response


HTTP/1.1 201 Created
Etag: "Ag"
Location: /sdk/v2/files/H3edQhgTissJUIYpAG7BnzmFja3p4KuBMEUq53IH
Vary: Origin
Date: Mon, 29 Aug 2016 19:18:19 GMT
Content-Length: 0
Content-Type: text/plain; charset=utf-8

Have question about this section?