Skip to content

Copying a File/Directory

Method

PUT

Endpoint URL

The xxxx.backendless.app is a subdomain assigned to your application. For more information see the Client-side Setup section of this documentation.

https://xxxx.backendless.app/api/files/copy

Request headers

Content-Type: application/json  
user-token: optional value obtained as a result of the login operation.

where:

Argument                Description
Content-Type Must be set to application/json. This header is mandatory.
user-token Optional header. Contains a value returned by Backendless in a preceding user Login API call. If user-token is set in the request, the currently logged in user will be assigned to the ownerId property of the user object which is being saved.  Additionally, the operation will be executed with the security policy associated currently logged in user. This means all permissions associated with the user and the roles assigned to the user will be enforced by Backendless.

Request Body:

A JSON object identifying a file or directory to be renamed and the new name:

{  
  "sourcePath" : source-path,  
  "targetPath": target-path  
}

where:

Argument                Description
source-path        - A path identifying file or directory to be copied. The path must start with the root directory of the remote file storage.
target-path        - A path to a directory where the source file or directory should be copied to. If the directory does not exist, it is created.

Return value

Absolute path to the copied file or directory.

Example

The example below describes how to copy a file called readme.txt located in the /documentationdirectory to the /updated-docs directory:

Important

Make sure to replace xxxx in the domain name in the sample request below to the one assigned to your application.

curl -H Content-Type: application/json -X PUT \  
-v https://xxxx.backendless.api/files/copy \  
-d "{ \"sourcePath\":\"/documentation/readme.txt\", \"targetPath\":\"/updated-docs\" }"

Errors

When the backend reports an error, it returns a JSON object in the following format:

{  
  "message":error-message,  
  "code":error-code  
}

The server may return the following errors:

Error Code
Error message
Notes
4000
User has no permissions to specified resource
Occurs when the user (anonymous or logged in) has no permission to modify the file
6000
File or directory cannot be found.
Occurs when the source file/directory cannot be found.
6006
Path contains prohibited symbols: {path name}

6007
The specified resource was not found
Occurs when the API requests to rename a non-existent file or a directory.
6018
Unable to modify file/folder: file/folder already exists: {file/directory name}
Occurs when the target file/directory already exists.
6028
Parameter {param name} cannot be null
Occurs when one of the parameters is null.
8010
Missing field {field name}
Occurs in REST APIs when one of the required fields is missing in the body.
8011
Content type should be 'application/json'
Occurs in REST API when the request's content type is not application/json

Codeless Reference

files_api_copy_file_directotry_1

where:

Argument                Description
from path A path identifying file or directory to be copied. The path must start with the root directory of the remote file storage.
to path A path to a directory where the source file or directory should be copied to. If the directory does not exist, a new one is created.
return URL of the copied directory/file When this box is checked, the operation returns a URL to the copied file or directory.

Returns the URL to the copied file or directory

Consider the following file and folder stored in the notes directory:

files_api_copy_file_directotry_2

The example below copies the "monday_food.txt" file to the "grocery" directory. The same operation can be also applied to a folder, not only to a file.

files_api_copy_file_directotry_3

The result of this operation will look as shown below after the Codeless logic runs:

files_api_copy_file_directotry_4