Operations (sample payloads)

Main operations

Convert file from Base64

Creates a new file from a Base64 encoded file. Sample Input

{
    "file": \{
        "name": "example.txt",
        "mime_type": "text/plain",
        "data": "SGVsbG8gV29ybGQh"
    \},
    "filename": "converted_example.txt"
}

Sample Output

{
    "file": \{
        "name": "converted_example.txt",
        "url": "https://example.com/files/converted_example.txt",
        "mime_type": "text/plain",
        "expires": 1623456789
    \}
}

Convert file to Base64

Creates a new Base64 encoded file from an original file. Sample Input

{
    "file": \{
        "name": "example.pdf",
        "url": "https://example.com/files/example.pdf",
        "mime_type": "application/pdf",
        "expires": 1623456789
    \},
    "filename": "converted_example.txt"
}

Sample Output

{
    "file": \{
        "name": "converted_example.txt",
        "url": "data:application/pdf;base64,JVBERi0xLjMNCiXi48/TDQoNCjEgMCBvYmoNCjw8DQovVHlwZSAvQ2F0YWxvZw0KL091dGxpbmVzIDIgMCBSDQovUGFnZXMgMyAwIFINCj4+DQplbmRvYmoNCg...",
        "mime_type": "text/plain",
        "expires": 1623456789
    \}
}

Convert to UTF-8 from URL

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

{
    "original_encoding": "ISO-8859-1",
    "url": "https://example.com/sample-file.txt",
    "name": "converted-file.txt",
    "headers": {
        "User-Agent": "Tray.io Connector"
    },
    "authentication": {
        "basic": \{
            "username": "user123",
            "password": "pass456"
        \}
    },
    "status_code": {
        "range": \{
            "start": 200,
            "end": 299
        \}
    }
}

Sample Output

{
    "file": \{
        "name": "converted-file.txt",
        "url": "https://tray-files.s3.amazonaws.com/converted-file-123456.txt",
        "mime_type": "text/plain",
        "expires": 1623456789
    \}
}

Create byte ranges list

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

{
    "file": \{
        "name": "example.pdf",
        "size": 1048576,
        "type": "application/pdf"
    \},
    "chunk_size": 262144
}

Sample Output

{
    "byteRanges": [
        \{
            "startByte": 0,
            "endByte": 262143
        \},
        \{
            "startByte": 262144,
            "endByte": 524287
        \},
        \{
            "startByte": 524288,
            "endByte": 786431
        \},
        \{
            "startByte": 786432,
            "endByte": 1048575
        \}
    ],
    "fileSize": 1048576
}

Create file from content

Create a file from some content. Sample Input

{
    "name": "customer_data.json",
    "content": \{
        "id": 12345,
        "name": "John Doe",
        "email": "johndoe@example.com",
        "age": 30,
        "active": true
    \},
    "base64_to_binary": false
}

Sample Output

{
    "file": \{
        "name": "customer_data.json",
        "url": "https://example.com/files/customer_data.json",
        "mime_type": "application/json",
        "expires": 1672531200
    \}
}

Create file from URL

Create a file by downloading from a given URL. Sample Input

{
    "url": "https://example.com/sample-file.pdf",
    "name": "important-document.pdf",
    "headers": {
        "User-Agent": "Tray.io File Downloader"
    },
    "authentication": {
        "basic": \{
            "username": "user123",
            "password": "pass456"
        \}
    },
    "status_code": {
        "range": \{
            "start": 200,
            "end": 299
        \}
    }
}

Sample Output

{
    "file": \{
        "name": "important-document.pdf",
        "url": "https://files.tray.io/12345/important-document.pdf",
        "mime_type": "application/pdf",
        "expires": 1623456789
    \},
    "status_code": 200,
    "headers": \{
        "Content-Type": "application/pdf",
        "Content-Length": "2048000",
        "Last-Modified": "Wed, 21 Oct 2023 07:28:00 GMT"
    \}
}

Get file size

Gets the size of a file in bytes. Sample Input

{
    "file": \{
        "name": "example.txt",
        "content": "VGhpcyBpcyBhIHNhbXBsZSBmaWxlIGNvbnRlbnQ=",
        "contentType": "text/plain",
        "size": 28
    \}
}

Sample Output

{
    "size": 28
}

Read file contents

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

{
    "url": "https://example.com/files/sample.txt",
    "name": "sample.txt",
    "headers": {
        "Accept": "text/plain"
    },
    "authentication": {
        "basic": \{
            "username": "user123",
            "password": "pass456"
        \}
    },
    "status_code": {
        "range": \{
            "start": 200,
            "end": 299
        \}
    }
}

Sample Output

{
    "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."
}

Read file contents as array

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

{
    "url": "https://example.com/sample.txt",
    "delimiter": ",",
    "use_regular_expressions": false,
    "name": "sample.txt",
    "headers": {
        "Accept": "text/plain"
    },
    "authentication": {
        "basic": \{
            "username": "user123",
            "password": "pass456"
        \}
    },
    "status_code": {
        "range": \{
            "start": 200,
            "end": 299
        \}
    },
    "limit": 5,
    "offset": 0
}

Sample Output

\{
    "result": [
        "apple",
        "banana",
        "cherry",
        "date",
        "elderberry"
    ]
\}

Upload file as form data

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

{
    "url": "https://api.example.com/upload",
    "method": "post",
    "form_data_properties": [
        {
            "file": \{
                "name": "document.pdf",
                "content": "base64encodedcontent..."
            \},
            "file_key": "uploaded_file"
        },
        \{
            "key": "description",
            "value": "Important document"
        \},
        \{
            "key": "user_id",
            "value": "12345"
        \}
    ],
    "headers": {
        "Authorization": "Bearer token123"
    },
    "send_content_length_header": true
}

Sample Output

{
    "success": true,
    "body": \{
        "message": "File uploaded successfully",
        "file_id": "abc123"
    \},
    "headers": \{
        "Content-Type": "application/json",
        "Server": "nginx/1.18.0"
    \},
    "status_code": 200
}

Upload file chunk

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

{
    "file": \{
        "name": "example.txt",
        "content": "VGhpcyBpcyBhIHNhbXBsZSBmaWxlIGNvbnRlbnQ=",
        "content_type": "text/plain"
    \},
    "url": "https://api.example.com/upload",
    "method": "put",
    "start_byte": 0,
    "end_byte": 1023,
    "headers": \{
        "Authorization": "Bearer token123",
        "Content-Type": "application/octet-stream"
    \}
}

Sample Output

{
    "success": true,
    "body": \{
        "message": "Chunk uploaded successfully",
        "bytes_received": 1024
    \},
    "headers": \{
        "Content-Type": "application/json",
        "Server": "nginx/1.18.0"
    \},
    "status_code": 200
}

Upload file to URL

Upload a file to a URL. Sample Input

{
    "file": \{
        "name": "example.pdf",
        "size": 1024000,
        "mime_type": "application/pdf"
    \},
    "url": "https://api.example.com/upload",
    "method": "post",
    "headers": \{
        "Authorization": "Bearer token123",
        "X-Custom-Header": "CustomValue"
    \},
    "return_response_as_file": true,
    "return_response_file_name": "upload_result.json"
}

Sample Output

{
    "body": \{
        "message": "File uploaded successfully",
        "file_id": "12345abcde"
    \},
    "headers": \{
        "Content-Type": "application/json",
        "Server": "nginx/1.18.0",
        "Date": "Mon, 15 May 2023 10:30:45 GMT"
    \},
    "status_code": 200,
    "success": true
}

Was this page helpful?