Uplo

Uplo

Handle file uploads to various storage services like Amazon S3, Google Cloud or etc. It also supports various type of ORM adapters, like Prisma.

Features

  • TypeScript ready
  • Direct uploads
  • Supports multiple services
  • Multiple ORM adapters
  • File analyzers

Getting started

Add @uplo/server (or @uplo/node if using Node) to your package.json

npm i @uplo/server

Install Adapter (for example Prisma)

npm i @uplo/adapter-prisma dataloader

Install Service (for example S3)

npm i @uplo/service-s3

Define uplo instance

import { createUplo } from '@uplo/server'
import { createPrismaAdapter } from '@uplo/adapter-prisma'
import { createS3Service } from '@uplo/service-s3'

const config = {
  privateKey: process.env.APPLICATION_SECRET, // Signs direct upload IDs, at least 32 bytes
  signedIdExpiresIn: 60 * 60, // Time how long a Signed ID is valid
}

const uplo = createUplo({
  config,
  adapter: createPrismaAdapter({ prisma }),
  services: {
    s3: createS3Service({
      isPublic: false,
      region: process.env.AWS_REGION,
      bucket: process.env.AWS_BUCKET,
      accessKeyId: '*****',
      secretAccessKey: '*****',
    }),
  },
  attachments: {},
})

privateKey signs the Signed IDs that clients receive, so it must be a random secret of at least 32 bytes. Shorter keys throw when Uplo is created. Generate one with:

openssl rand -base64 32

Without privateKey, attachFile still works, but direct uploads fail.

On this page