File Manager
The File Manager API handles standard filesystem operations such as renaming, moving, copying, deleting files, and creating new directories.
Base Endpoint: POST /rest/2.0/xpan/file
All operations in this section share a common endpoint but differ by the method or opera (operation) parameter.
Common Requirements:
* bdstoken: Required for all write operations.
* jsToken: Required for all operations.
* POST Data: Most operations expect a form-encoded body containing a filelist JSON string.
1. Rename
Renames a file or directory in place.
Parameters:
* method: filemanager
* opera: rename
Body Data:
* filelist: A JSON array of objects, each containing path (current full path) and newname (just the new name, not full path).
=== "cURL"
```bash
curl -X POST "https://1024terabox.com/rest/2.0/xpan/file?method=filemanager&opera=rename&bdstoken=TOKEN&jsToken=TOKEN" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "filelist=[{\"path\":\"/old_name.txt\",\"newname\":\"new_name.txt\"}]"
```
=== "Python"
```python
import json
# Define the rename task
filelist = [
{"path": "/old_name.txt", "newname": "new_name.txt"}
]
params = {
'method': 'filemanager',
'opera': 'rename',
'bdstoken': bdstoken,
'jsToken': js_token
}
# Payload must be a JSON string inside 'filelist'
data = {'filelist': json.dumps(filelist)}
resp = session.post('https://1024terabox.com/rest/2.0/xpan/file', params=params, data=data)
print(resp.json())
```
=== "Node.js"
```javascript
const filelist = JSON.stringify([
{ path: "/old_name.txt", newname: "new_name.txt" }
]);
await client.post('/rest/2.0/xpan/file',
`filelist=${encodeURIComponent(filelist)}`,
{
params: {
method: 'filemanager',
opera: 'rename',
bdstoken: 'TOKEN',
jsToken: 'TOKEN'
}
}
);
```
2. Move / Copy
Moves or Copies files from a source path to a destination directory.
Parameters:
* method: filemanager
* opera: move OR copy
Body Data:
* filelist: A JSON array of objects, each containing:
* path: The full path of the source file.
* dest: The full path of the destination directory.
* newname: The name the file should have in the destination (usually same as source name).
=== "cURL"
```bash
# Move Example
curl -X POST "https://1024terabox.com/rest/2.0/xpan/file?method=filemanager&opera=move&bdstoken=TOKEN&jsToken=TOKEN" \
-d "filelist=[{\"path\":\"/source.txt\",\"dest\":\"/target_folder\",\"newname\":\"source.txt\"}]"
```
=== "Python"
```python
# Move Example
filelist = [
{"path": "/source/file.txt", "dest": "/target_folder", "newname": "file.txt"}
]
params = {
'method': 'filemanager',
'opera': 'move', # Change to 'copy' for copying
'bdstoken': bdstoken,
'jsToken': js_token
}
data = {'filelist': json.dumps(filelist)}
session.post(url, params=params, data=data)
```
=== "Node.js"
```javascript
// Move Example
const filelist = JSON.stringify([
{ path: "/source.txt", dest: "/target", newname: "source.txt" }
]);
await client.post('/rest/2.0/xpan/file',
`filelist=${encodeURIComponent(filelist)}`,
{
params: {
method: 'filemanager',
opera: 'move', // or 'copy'
bdstoken: 'TOKEN',
jsToken: 'TOKEN'
}
}
);
```
3. Delete
Permanently deletes files or folders. Usually sends them to the Recycle Bin.
Parameters:
* method: filemanager
* opera: delete
Body Data:
* filelist: A simple JSON array of strings, where each string is a full path to delete.
=== "cURL"
```bash
curl -X POST "https://1024terabox.com/rest/2.0/xpan/file?method=filemanager&opera=delete&bdstoken=TOKEN&jsToken=TOKEN" \
-d "filelist=[\"/file1.txt\",\"/folder1\"]"
```
=== "Python"
```python
# List of paths to delete
target_paths = ["/file1.txt", "/folder1"]
params = {
'method': 'filemanager',
'opera': 'delete',
'bdstoken': bdstoken,
'jsToken': js_token
}
data = {'filelist': json.dumps(target_paths)}
session.post(url, params=params, data=data)
```
=== "Node.js"
```javascript
const targetPaths = JSON.stringify(["/file1.txt", "/folder1"]);
await client.post('/rest/2.0/xpan/file',
`filelist=${encodeURIComponent(targetPaths)}`,
{
params: {
method: 'filemanager',
opera: 'delete',
bdstoken: 'TOKEN',
jsToken: 'TOKEN'
}
}
);
```
4. Make Directory (Mkdir)
Creates a new directory. This uses a different method parameter (create) than the others.
Parameters:
* method: create
Body Data:
* path: Full path of the new directory.
* isdir: Always 1.
* size: Always 0.
* block_list: Always [].
* rtype: Always 1.
=== "cURL"
```bash
curl -X POST "https://1024terabox.com/rest/2.0/xpan/file?method=create&bdstoken=TOKEN&jsToken=TOKEN" \
-d "path=/NewFolder&isdir=1&size=0&block_list=[]&rtype=1"
```
=== "Python"
```python
params = {
'method': 'create',
'bdstoken': bdstoken,
'jsToken': js_token
}
data = {
'path': '/NewFolder',
'isdir': '1',
'size': '0',
'block_list': '[]',
'rtype': '1'
}
resp = session.post(url, params=params, data=data)
```
=== "Node.js"
```javascript
const qs = require('qs');
const data = qs.stringify({
path: '/NewFolder',
isdir: 1,
size: 0,
block_list: '[]',
rtype: 1
});
await client.post('/rest/2.0/xpan/file', data, {
params: { method: 'create', bdstoken: 'TOKEN', jsToken: 'TOKEN' }
});
```