Skip to content

Sending files

Several of our services expect to receive documents in order to run the analysis. Files can be sent in two ways:

  1. Multipart - form-data

The file can be sent in the request as "multipart/form-data". This is the recommended way and is easy to implement across languages and tools.

shell
curl --request POST \
  --url 'https://example-url.nxcd.app/endpoint' \
  --header 'Authorization: ApiKey <TOKEN>' \
  --header 'Content-Type: multipart/form-data' \
  --form 'frente=@/documento-frente-exemplo.jpg' \
  --form 'verso=@/documento-verso-exemplo.jpg'
js
const form = new FormData();
form.append("frente", "./documento-frente-exemplo.jpg");
form.append("verso", "./documento-verso-exemplo.jpg");

const options = {
  method: 'POST',
  headers: {
    'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001',
    Authorization: 'ApiKey <TOKEN>'
  }
};

options.body = form;

fetch('https://example-url.nxcd.app/endpoint', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
js
import axios from "axios";

const form = new FormData();
form.append("frente", "./documento-frente-exemplo.jpg");
form.append("verso", "./documento-verso-exemplo.jpg");

const options = {
  method: 'POST',
  url: 'https://example-url.nxcd.app/endpoint',
  params: {
  },
  headers: {
    'Content-Type': 'multipart/form-data; boundary=---011000010111000001101001',
    Authorization: 'ApiKey <TOKEN>'
  },
  data: '[form]'
};

axios.request(options).then(function (response) {
  console.log(response.data);
}).catch(function (error) {
  console.error(error);
});
python
import requests

url = "https://example-url.nxcd.app/endpoint"

querystring = {}

payload = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"frente\"; filename=\"documento-frente-exemplo.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"verso\"; filename=\"documento-verso-exemplo.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n-----011000010111000001101001--\r\n"
headers = {
    "Content-Type": "multipart/form-data; boundary=---011000010111000001101001",
    "Authorization": "<TOKEN>"
}

response = requests.request("POST", url, data=payload, headers=headers, params=querystring)

print(response.text)
elixir
response = HTTPoison.post!(
  "https://example-url.nxcd.app/endpoint",
  {:multipart, [
    {:file, "/documento-frente-exemplo.jpg", {"form-data", [{:name, "frente"}, {:filename, Path.basename("/documento-frente-exemplo.jpg")}]}, []},
    {:file, "/documento-verso-exemplo.jpg", {"form-data", [{:name, "verso"}, {:filename, Path.basename("/documento-verso-exemplo.jpg")}]}, []}
  ]},
  [
    {"Authorization", "ApiKey <TOKEN>"},
    {"Content-Type", "multipart/form-data"}
  ]
)
dart
import 'package:http/http.dart' as http;

void main() async {
  final url = Uri.parse('https://example-url.nxcd.app/endpoint');

  final req = http.MultipartRequest('POST', url)
    ..files.add(await http.MultipartFile.fromPath(
      'frente', '/documento-frente-exemplo.jpg'))
    ..files.add(await http.MultipartFile.fromPath(
      'verso', '/documento-verso-exemplo.jpg'));

  req.headers['Authorization'] = 'ApiKey <TOKEN>';
  req.headers['Content-Type'] = 'multipart/form-data';

  final stream = await req.send();
  final res = await http.Response.fromStream(stream);
  final status = res.statusCode;
  if (status != 200) throw Exception('http.send error: statusCode= $status');

  print(res.body);
}
  1. Base64

Files can also be sent as the base64 of the original image, in JSON, in the request body, as shown below:

json
{
  "base64": {
    "arquivo1": "BASE_64_1_HERE",
    "arquivo2": "BASE_64_2_HERE"
  }
}

🚧 Sending files by URL is deprecated

Sending the file by URL, in the urls field, has been deprecated and is no longer part of this documentation. Integrations that still rely on it should migrate to multipart/form-data or to the base64 field.

Limits

The limits below apply to every API and are enforced before the file is processed.

LimitValueWhere it applies
Size of each file15 MBmultipart/form-data uploads
Size of each form field5 MBmultipart/form-data uploads
JSON body size50 MBbase64 uploads
Request body size at the edge100 MBAll upload methods
  • Multipart: each file can be up to 15 MB and each form field up to 5 MB. A file above the limit gets a 413 Payload Too Large.
  • Base64: the encoded content travels in the JSON body and is subject to the 50 MB limit. Keep in mind that base64 encoding inflates the original file size by about a third.

WARNING

A JSON body above 50 MB is rejected before the application generates the request identifier: the response comes back with code 500 and id: null. Above 100 MB, the request is blocked at the edge and the response is not even JSON. In both cases, the request identifier remains available in the Nextid-ReqId header.

Nextcode | Identity Verification Solutions