Create a new file or folder


Create a new file or folder.

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

Request Syntax

POST /v2/files


Request Headers

ParameterDescriptionRequired
AuthorizationAn 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-TypeIndicates the content type of the returned content. The value must be multipart/related.

Value of type: string
true


Request Query Parameters

ParameterDescriptionRequired
resolveNameConflictIf 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

ParameterDescriptionRequired
Body part 1: cTimeThe file creation time.

Value of type: dateTime

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

Value of type: string

Default: none
false
Body part 1: mimeTypeThe 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: mimeTypesList 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: mTimeThe file modification time.

Value of type: dateTime

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

Value of type: string

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

Value of type: string

Default: root
false
Body part 2The 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 3The 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

ParameterDescriptionRequired
ETagAn 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
LocationA 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.1Host: Endpoint-URLAuthorization: Bearer 25951a7e-ffae-4edb-abb2-5e57d4ffb759Content-Type: multipart/related;boundary=foo--foo{  "name": "newfile",  "parentID": "root"}--foocontents of file--foo--

Response

HTTP/1.1 201 CreatedEtag: "Ag"Location: /sdk/v2/files/SCtt6sReL85MCZ-Ds-MrAVR67JkbpPqLKzqpyQnlVary: OriginDate: Mon, 29 Aug 2016 19:18:19 GMTContent-Length: 0Content-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.1Host: Endpoint-URLAuthorization: Bearer 25951a7e-ffae-4edb-abb2-5e57d4ffb759Content-Type: multipart/related;boundary=foo--foo{  "name": "live_photo.heic",  "parentID": "root",  "mimeTypes": ["image/heic", "video/quicktime"]}--fooContent-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 CreatedEtag: "Ag"Location: /sdk/v2/files/H3edQhgTissJUIYpAG7BnzmFja3p4KuBMEUq53IHVary: OriginDate: Mon, 29 Aug 2016 19:18:19 GMTContent-Length: 0Content-Type: text/plain; charset=utf-8