Fency.ai
Memory uploads

Uploading files for memories

Create a file memory, get a presigned upload URL, and upload the file from your server.

This guide walks through the full process of uploading a file to create a memory in Fency.ai. File memories can then be used as context in Explore memories.

The upload flow consists of three steps: creating an empty file memory, obtaining a presigned upload URL, and uploading the file directly to that URL. These calls are made from your server using your secret key.

Step 1: Create a memory

Call Create file memory (POST /v1/memories with sourceType: "FILE") to create an empty memory record. This returns a memoryId you will use in the next step.

Step 2: Create an upload for the memory

Call Create memory upload (POST /v1/memories/:id/uploads) with the file's fileName, fileSize, and mimeType. This returns an awsS3PostRequest object containing a presigned S3 upload URL along with the required form fields.

Step 3: Upload the file

Post a FormData payload containing all the returned S3 fields plus the file itself to the presigned uploadUrl.

// Step 1: Create a memory with sourceType FILE
const createMemoryResponse = await fetch('https://api.fency.ai/v1/memories', {
    method: 'POST',
    headers: {
        Authorization: `Bearer ${process.env.FENCY_SECRET_KEY}`,
        'Content-Type': 'application/json',
    },
    body: JSON.stringify({
        memoryTypeId: 'mty_...',
        sourceType: 'FILE',
        title: 'My document',
    }),
})
const { memoryId } = await createMemoryResponse.json()

// Step 2: Create an upload for the memory to get a presigned URL
const createUploadResponse = await fetch(
    `https://api.fency.ai/v1/memories/${memoryId}/uploads`,
    {
        method: 'POST',
        headers: {
            Authorization: `Bearer ${process.env.FENCY_SECRET_KEY}`,
            'Content-Type': 'application/json',
        },
        body: JSON.stringify({
            fileName: file.name,
            fileSize: file.size,
            mimeType: file.type,
        }),
    }
)
const { awsS3PostRequest } = await createUploadResponse.json()

// Step 3: Upload the file directly to the presigned URL
const formData = new FormData()
formData.append('key', awsS3PostRequest.key)
formData.append('policy', awsS3PostRequest.policy)
formData.append('x-amz-algorithm', awsS3PostRequest.amzAlgorithm)
formData.append('x-amz-credential', awsS3PostRequest.amzCredential)
formData.append('x-amz-date', awsS3PostRequest.amzDate)
formData.append('x-amz-signature', awsS3PostRequest.amzSignature)
formData.append('x-amz-security-token', awsS3PostRequest.sessionToken)
formData.append('file', file)

await fetch(awsS3PostRequest.uploadUrl, {
    method: 'POST',
    body: formData,
})

Knowing when the memory is ready

After the upload completes, Fency processes the file asynchronously. Once the memory is ready to use, a memory.updated webhook event is sent to your registered webhook endpoint. See Events in the API reference for the event payload.

For full details on the request parameters, see Create file memory and Create memory upload.

On this page