Base64 encoding
File upload endpoints accept base64-encoded strings that represent the file to upload. Most programming languages can convert files to base64 strings. If your API client does not support this directly, use a separate conversion tool before sending the request.# Encode a file to Base64 and send in a JSON payload
BASE64_FILE=$(base64 -w 0 document.pdf)
curl -X POST "https://api.us.cr4ce.com/entry/{entry_slug}/upload/{field_slug}" \
-H "Accept: application/vnd.Creative Force.v2.3+json" \
-H "x-api-key: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d "{\"file\": \"$BASE64_FILE\", \"filename\": \"document.pdf\"}"
# The -w 0 flag prevents line wrapping in the Base64 output
$fileContent = file_get_contents('/path/to/your/file.pdf');
$base64 = base64_encode($fileContent);
$payload = json_encode([
'file' => $base64,
'filename' => 'document.pdf'
]);
$ch = curl_init('https://api.us.cr4ce.com/entry/{entry_slug}/upload/{field_slug}');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: application/vnd.Creative Force.v2.3+json',
'x-api-key: YOUR_API_KEY',
'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
const fs = require('fs');
const https = require('https');
const fileBuffer = fs.readFileSync('/path/to/your/file.pdf');
const base64 = fileBuffer.toString('base64');
const payload = JSON.stringify({
file: base64,
filename: 'document.pdf'
});
const options = {
hostname: 'api.us.cr4ce.com',
path: '/entry/{entry_slug}/upload/{field_slug}',
method: 'POST',
headers: {
'Accept': 'application/vnd.Creative Force.v2.3+json',
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(payload)
}
};
const req = https.request(options, (res) => {
let data = '';
res.on('data', (chunk) => data += chunk);
res.on('end', () => console.log(data));
});
req.write(payload);
req.end();
import base64
import json
import requests
with open('/path/to/your/file.pdf', 'rb') as f:
base64_content = base64.b64encode(f.read()).decode('utf-8')
response = requests.post(
'https://api.us.cr4ce.com/entry/{entry_slug}/upload/{field_slug}',
headers={
'Accept': 'application/vnd.Creative Force.v2.3+json',
'x-api-key': 'YOUR_API_KEY',
'Content-Type': 'application/json'
},
json={
'file': base64_content,
'filename': 'document.pdf'
}
)
using System;
using System.IO;
using System.Net.Http;
using System.Text.Json;
using System.Threading.Tasks;
var fileBytes = File.ReadAllBytes("/path/to/your/file.pdf");
var base64 = Convert.ToBase64String(fileBytes);
var payload = new
{
file = base64,
filename = "document.pdf"
};
using var client = new HttpClient();
client.DefaultRequestHeaders.Add("Accept", "application/vnd.Creative Force.v2.3+json");
client.DefaultRequestHeaders.Add("x-api-key", "YOUR_API_KEY");
var json = JsonSerializer.Serialize(payload);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var response = await client.PostAsync("https://api.us.cr4ce.com/entry/{entry_slug}/upload/{field_slug}", content);
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Base64;
var fileBytes = Files.readAllBytes(Paths.get("/path/to/your/file.pdf"));
var base64 = Base64.getEncoder().encodeToString(fileBytes);
var json = String.format(
"{\"file\":\"%s\",\"filename\":\"document.pdf\"}", base64
);
var client = HttpClient.newHttpClient();
var request = HttpRequest.newBuilder()
.uri(URI.create("https://api.us.cr4ce.com/entry/{entry_slug}/upload/{field_slug}"))
.header("Accept", "application/vnd.Creative Force.v2.3+json")
.header("x-api-key", "YOUR_API_KEY")
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(json))
.build();
var response = client.send(request, HttpResponse.BodyHandlers.ofString());