Operations (sample payloads)

Main operations
Copy

Convert file from Base64
Copy

Creates a new file from a Base64 encoded file.

Sample Input

1
{
2
"file": {
3
"name": "example.txt",
4
"mime_type": "text/plain",
5
"data": "SGVsbG8gV29ybGQh"
6
},
7
"filename": "converted_example.txt"
8
}

Sample Output

1
{
2
"file": {
3
"name": "converted_example.txt",
4
"url": "https://example.com/files/converted_example.txt",
5
"mime_type": "text/plain",
6
"expires": 1623456789
7
}
8
}

Convert file to Base64
Copy

Creates a new Base64 encoded file from an original file.

Sample Input

1
{
2
"file": {
3
"name": "example.pdf",
4
"url": "https://example.com/files/example.pdf",
5
"mime_type": "application/pdf",
6
"expires": 1623456789
7
},
8
"filename": "converted_example.txt"
9
}

Sample Output

1
{
2
"file": {
3
"name": "converted_example.txt",
4
"url": "data:application/pdf;base64,JVBERi0xLjMNCiXi48/TDQoNCjEgMCBvYmoNCjw8DQovVHlwZSAvQ2F0YWxvZw0KL091dGxpbmVzIDIgMCBSDQovUGFnZXMgMyAwIFINCj4+DQplbmRvYmoNCg...",
5
"mime_type": "text/plain",
6
"expires": 1623456789
7
}
8
}

Convert to UTF-8 from URL
Copy

Creates a new file encoded into UTF-8 encoding, from an original file, using an URL.

Sample Input

1
{
2
"original_encoding": "ISO-8859-1",
3
"url": "https://example.com/sample-file.txt",
4
"name": "converted-file.txt",
5
"headers": {
6
"User-Agent": "Tray.io Connector"
7
},
8
"authentication": {
9
"basic": {
10
"username": "user123",
11
"password": "pass456"
12
}
13
},
14
"status_code": {
15
"range": {
16
"start": 200,
17
"end": 299
18
}
19
}
20
}

Sample Output

1
{
2
"file": {
3
"name": "converted-file.txt",
4
"url": "https://tray-files.s3.amazonaws.com/converted-file-123456.txt",
5
"mime_type": "text/plain",
6
"expires": 1623456789
7
}
8
}

Create byte ranges list
Copy

Create a list of byte range arrays for use with chunked uploads.

Sample Input

1
{
2
"file": {
3
"name": "example.pdf",
4
"size": 1048576,
5
"type": "application/pdf"
6
},
7
"chunk_size": 262144
8
}

Sample Output

1
{
2
"byteRanges": [
3
{
4
"startByte": 0,
5
"endByte": 262143
6
},
7
{
8
"startByte": 262144,
9
"endByte": 524287
10
},
11
{
12
"startByte": 524288,
13
"endByte": 786431
14
},
15
{
16
"startByte": 786432,
17
"endByte": 1048575
18
}
19
],
20
"fileSize": 1048576
21
}

Create file from content
Copy

Create a file from some content.

Sample Input

1
{
2
"name": "customer_data.json",
3
"content": {
4
"id": 12345,
5
"name": "John Doe",
6
"email": "johndoe@example.com",
7
"age": 30,
8
"active": true
9
},
10
"base64_to_binary": false
11
}

Sample Output

1
{
2
"file": {
3
"name": "customer_data.json",
4
"url": "https://example.com/files/customer_data.json",
5
"mime_type": "application/json",
6
"expires": 1672531200
7
}
8
}

Create file from URL
Copy

Create a file by downloading from a given URL.

Sample Input

1
{
2
"url": "https://example.com/sample-file.pdf",
3
"name": "important-document.pdf",
4
"headers": {
5
"User-Agent": "Tray.io File Downloader"
6
},
7
"authentication": {
8
"basic": {
9
"username": "user123",
10
"password": "pass456"
11
}
12
},
13
"status_code": {
14
"range": {
15
"start": 200,
16
"end": 299
17
}
18
}
19
}

Sample Output

1
{
2
"file": {
3
"name": "important-document.pdf",
4
"url": "https://files.tray.io/12345/important-document.pdf",
5
"mime_type": "application/pdf",
6
"expires": 1623456789
7
},
8
"status_code": 200,
9
"headers": {
10
"Content-Type": "application/pdf",
11
"Content-Length": "2048000",
12
"Last-Modified": "Wed, 21 Oct 2023 07:28:00 GMT"
13
}
14
}

Get file size
Copy

Gets the size of a file in bytes.

Sample Input

1
{
2
"file": {
3
"name": "example.txt",
4
"content": "VGhpcyBpcyBhIHNhbXBsZSBmaWxlIGNvbnRlbnQ=",
5
"contentType": "text/plain",
6
"size": 28
7
}
8
}

Sample Output

1
{
2
"size": 28
3
}

Read file contents
Copy

Reads a file's contents and outputs it as a string.

Sample Input

1
{
2
"url": "https://example.com/files/sample.txt",
3
"name": "sample.txt",
4
"headers": {
5
"Accept": "text/plain"
6
},
7
"authentication": {
8
"basic": {
9
"username": "user123",
10
"password": "pass456"
11
}
12
},
13
"status_code": {
14
"range": {
15
"start": 200,
16
"end": 299
17
}
18
}
19
}

Sample Output

1
{
2
"result": "This is the content of the sample.txt file.\nIt can contain multiple lines of text.\nThe file contents are returned as a string."
3
}

Read file contents as array
Copy

Read a file's contents and output it as an array.

Sample Input

1
{
2
"url": "https://example.com/sample.txt",
3
"delimiter": ",",
4
"use_regular_expressions": false,
5
"name": "sample.txt",
6
"headers": {
7
"Accept": "text/plain"
8
},
9
"authentication": {
10
"basic": {
11
"username": "user123",
12
"password": "pass456"
13
}
14
},
15
"status_code": {
16
"range": {
17
"start": 200,
18
"end": 299
19
}
20
},
21
"limit": 5,
22
"offset": 0
23
}

Sample Output

1
{
2
"result": [
3
"apple",
4
"banana",
5
"cherry",
6
"date",
7
"elderberry"
8
]
9
}

Upload file as form data
Copy

Upload a file to a URL as part of a 'FormData' object.

Sample Input

1
{
2
"url": "https://api.example.com/upload",
3
"method": "post",
4
"form_data_properties": [
5
{
6
"file": {
7
"name": "document.pdf",
8
"content": "base64encodedcontent..."
9
},
10
"file_key": "uploaded_file"
11
},
12
{
13
"key": "description",
14
"value": "Important document"
15
},
16
{
17
"key": "user_id",
18
"value": "12345"
19
}
20
],
21
"headers": {
22
"Authorization": "Bearer token123"
23
},
24
"send_content_length_header": true
25
}

Sample Output

1
{
2
"success": true,
3
"body": {
4
"message": "File uploaded successfully",
5
"file_id": "abc123"
6
},
7
"headers": {
8
"Content-Type": "application/json",
9
"Server": "nginx/1.18.0"
10
},
11
"status_code": 200
12
}

Upload file chunk
Copy

Upload a chunk of a file. See documentation for an example use case.

Sample Input

1
{
2
"file": {
3
"name": "example.txt",
4
"content": "VGhpcyBpcyBhIHNhbXBsZSBmaWxlIGNvbnRlbnQ=",
5
"content_type": "text/plain"
6
},
7
"url": "https://api.example.com/upload",
8
"method": "put",
9
"start_byte": 0,
10
"end_byte": 1023,
11
"headers": {
12
"Authorization": "Bearer token123",
13
"Content-Type": "application/octet-stream"
14
}
15
}

Sample Output

1
{
2
"success": true,
3
"body": {
4
"message": "Chunk uploaded successfully",
5
"bytes_received": 1024
6
},
7
"headers": {
8
"Content-Type": "application/json",
9
"Server": "nginx/1.18.0"
10
},
11
"status_code": 200
12
}

Upload file to URL
Copy

Upload a file to a URL.

Sample Input

1
{
2
"file": {
3
"name": "example.pdf",
4
"size": 1024000,
5
"mime_type": "application/pdf"
6
},
7
"url": "https://api.example.com/upload",
8
"method": "post",
9
"headers": {
10
"Authorization": "Bearer token123",
11
"X-Custom-Header": "CustomValue"
12
},
13
"return_response_as_file": true,
14
"return_response_file_name": "upload_result.json"
15
}

Sample Output

1
{
2
"body": {
3
"message": "File uploaded successfully",
4
"file_id": "12345abcde"
5
},
6
"headers": {
7
"Content-Type": "application/json",
8
"Server": "nginx/1.18.0",
9
"Date": "Mon, 15 May 2023 10:30:45 GMT"
10
},
11
"status_code": 200,
12
"success": true
13
}