Secure file uploads with presigned URLs

Let users upload straight from the browser without exposing your API key or bucket. Your backend asks Dreep for a single-use upload URL, the browser PUTs the file, and Dreep checks type, size and headers before it goes live.

The three-step presigned upload flow

  1. 1

    Browser

    Asks your backend to upload a file

  2. 2

    Your backend

    Authorises the user, calls presign

  3. 3

    Browser PUT

    Raw bytes to the single-use uploadUrl

  4. 4

    Your backend

    Calls confirm with the upload id

  5. 5

    Asset ready

    pending until confirmed

Your API key stays on your server. The browser only ever holds a URL that works once, for 10 minutes, for one file.

Authorise, then presign

Two small endpoints. The first authorises the user and calls presign with a folder scoped to that user. The second checks the upload belongs to the caller and confirms it.

const dreep = new Dreep({ apiKey: process.env.DREEP_API_KEY });

// requireUser is your own auth middleware
app.post("/uploads", requireUser, async (req, res) => {
  const { filename, contentType, sizeBytes } = req.body;
  const upload = await dreep.presignUpload({
    filename,
    contentType,
    sizeBytes,
    folder: `users/${req.user.id}`,
  });
  res.json({ id: upload.id, uploadUrl: upload.uploadUrl });
});

// Check the upload belongs to req.user before confirming
app.post("/uploads/:id/confirm", requireUser, async (req, res) => {
  const asset = await dreep.confirmUpload({ id: req.params.id });
  res.json({ id: asset.id, url: asset.url });
});

What you get

Your key stays server-side

The upload URL needs no API key and works once, for one file, for 10 minutes.

The upload contract is enforced

Dreep rejects types outside the allow-list, files over 500 MB and PUTs whose headers do not match presign.

Public, Signed or Private

Choose the folder at presign time to decide who can read the file afterwards.

Frequently asked questions

How do I upload from the browser without exposing my API key?

Your backend authenticates the user and calls POST /api/v1/upload/presign with the API key. It returns an upload id and an uploadUrl. The browser PUTs the file to uploadUrl, which needs no key, and your backend calls confirm. The key never leaves your server.

How long is a presigned upload URL valid?

10 minutes, and it can be used once. Request a new one per file.

What happens if the browser sends a different file type or size?

The PUT is rejected. Content-Type and Content-Length must match the contentType and sizeBytes your backend declared at presign time, so a client cannot swap in a larger file or a different type.

Does Dreep scan uploads for malware?

No. Dreep validates type, size and headers, but does not scan file contents for malware or moderate them. If you accept documents or archives from the public, run your own scanning.

Related

Ship browser uploads without leaking your key

Create a project, add two endpoints to your backend, and your users upload directly with single-use URLs.