Afriex SDK
API Reference

Media API

Upload a file and get back the key that other requests take.

Upload a File

import { readFile } from "node:fs/promises";

const { key } = await afriex.media.upload({
  fileName: "invoice-1042.pdf",
  type: "transaction",
  file: await readFile("./invoice-1042.pdf"),
  contentType: "application/pdf",
});

Parameters:

FieldTypeRequiredDescription
fileNamestringYesThe name of the file
fileBlob | ArrayBuffer | Uint8ArrayYesThe file contents. A Node.js Buffer is a Uint8Array
type"transaction" | "user"-What the file is for. Defaults to user
contentTypestring-Sent as the Content-Type of the upload

upload() requests an upload URL, sends the file to it, and returns { key }. The upload goes to the storage host, so it is sent without your API key.

Where the Key Goes

The file isUpload it with typePass the key as
An invoice for a SWIFT withdrawaltransactionmeta.invoice on transactions.create()
A pool-account payment prooftransactionfileKey on transactions.submitPoolAccountProof()
An identity documentuserThe document field that asks for it

transaction and user files are stored apart. A payment proof uploaded without type: "transaction" uploads successfully and is then rejected as not found when you submit it.

Create an Upload URL

Use createUploadUrl() when something other than your server sends the file, such as a browser.

const { url, key, expiresIn } = await afriex.media.createUploadUrl({
  fileName: "passport.png",
  type: "user",
});

// Send the file with PUT before the URL expires
await fetch(url, { method: "PUT", body: file });
FieldTypeDescription
urlstringThe presigned URL to PUT the file to
keystringThe reference to pass to later requests
expiresInnumberHow many seconds the URL stays valid for the upload, usually 300

Later requests take the key. No endpoint accepts the presigned URL.

On this page