Part of Hosting by frameworkHosting · Files

Uploading and serving private files through your app.

On Canner the S3 endpoint your app gets is internal, so a presigned URL points at an address no browser can reach. Send uploads to a route in your app that writes them to the bucket, and serve downloads through a route that checks the user, then streams the object. Here is the code for Express, Django, Rails and Laravel.

Facts checked

Why presigned URLs don’t work here

A presigned URL is the bucket’s own address plus a signature that grants time-limited access. That only helps if the browser can reach the bucket. On Canner the storage endpoint is on the same host as your app (127.0.0.1), reachable only from your app’s server code, with no public endpoint. A presigned URL made with these credentials sends the visitor’s browser to 127.0.0.1, which is their own computer, so the image or download fails with a connection error or a mixed-content block.

So the app sits in the middle both ways. The browser posts the file to your app, which writes it to the bucket. The browser asks your app for the file, and your app checks the user, reads the object and streams it back. It costs you a little memory and bandwidth, and gives you one place where access is checked on every request.

What turns into a presigned URL, framework by framework

Most storage libraries hand you a presigned URL without saying so. These are the calls to stop using, and what to do instead:

StackGives you a presigned URLUse instead
Node (AWS SDK v3) †getSignedUrl() from @aws-sdk/s3-request-presigner, for uploads and downloadsA route that pipes GetObjectCommand’s Body to the response
Django (django-storages) †FieldFile.url / {{ file.url }}, signed because querystring_auth defaults to TrueA view that returns FileResponse(file.open("rb"))
Rails (Active Storage) † †url_for(attachment) and rails_blob_path (redirect mode), and direct uploads (direct_upload: true presigns a PUT)A controller with send_blob_stream; plain form uploads
Laravel †Storage::temporaryUrl() and temporaryUploadUrl()Storage::disk(...)->download() or ->response() in a route

† Competitor details come from each vendor’s own published pages on the dates shown; prices and plans change, so check the vendor before you decide. Node (AWS SDK v3) (2026-10-29) · Django (django-storages) (2026-10-29) · Rails (Active Storage) (2026-10-29) · Rails (Active Storage) (2026-10-29) · Laravel (2026-10-29)

Express and the AWS SDK

The upload goes through multer with a size limit, gets a random key under the project prefix, and the key is saved with the owner in your database. The download looks the row up, answers 404 if it belongs to someone else, and pipes the object’s body to the response so a large file never sits in memory whole.

Memory storage is fine for files of a few megabytes. Starter apps have 512 MB of memory, so for larger uploads use multer’s disk storage or stream the request into @aws-sdk/lib-storage’s Upload instead.

// Express: upload to the bucket, download through a route that checks the user
import express from "express";
import multer from "multer";
import { randomUUID } from "node:crypto";
import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";

const s3 = new S3Client({
  endpoint: process.env.CANNER_STORAGE_ENDPOINT,
  region: process.env.CANNER_STORAGE_REGION,
  credentials: {
    accessKeyId: process.env.CANNER_STORAGE_ACCESS_KEY_ID,
    secretAccessKey: process.env.CANNER_STORAGE_SECRET_ACCESS_KEY,
  },
  forcePathStyle: true,
});
const Bucket = process.env.CANNER_STORAGE_BUCKET;
const PREFIX = "your-project"; // your project's slug: every key must start with it

const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 20 * 1024 * 1024 } });

app.post("/files", requireUser, upload.single("file"), async (req, res) => {
  const key = `${PREFIX}/users/${req.user.id}/${randomUUID()}`;
  await s3.send(new PutObjectCommand({
    Bucket, Key: key, Body: req.file.buffer, ContentType: req.file.mimetype,
  }));
  const doc = await db.documents.create({
    ownerId: req.user.id, key, name: req.file.originalname, type: req.file.mimetype,
  });
  res.status(201).json({ id: doc.id });
});

app.get("/files/:id", requireUser, async (req, res) => {
  const doc = await db.documents.find(req.params.id);
  if (!doc || doc.ownerId !== req.user.id) return res.sendStatus(404); // not 403: don't confirm it exists
  const obj = await s3.send(new GetObjectCommand({ Bucket, Key: doc.key }));
  res.set({
    "Content-Type": doc.type,
    "Content-Length": String(obj.ContentLength),
    "Content-Disposition": `attachment; filename*=UTF-8''${encodeURIComponent(doc.name)}`,
    "Cache-Control": "private, no-store",
    "X-Content-Type-Options": "nosniff",
  });
  obj.Body.pipe(res); // streamed, never held in memory whole
});

Django with django-storages

Put the bucket in the default storage and keep staticfiles on the filesystem (or WhiteNoise): static assets are part of the build, and serving them from a private bucket would mean signed URLs again. location puts every key under your project slug.

Reading a file through django-storages downloads the whole object into a temporary file first, then FileResponse sends it in chunks. With the default max_memory_size of 0, that temporary file stays in memory, whatever its size. Set it, as below, so large files go to disk instead.

# settings.py (django-storages 1.14+)
import os

STORAGES = {
    "default": {
        "BACKEND": "storages.backends.s3.S3Storage",
        "OPTIONS": {
            "endpoint_url": os.environ["CANNER_STORAGE_ENDPOINT"],
            "region_name": os.environ["CANNER_STORAGE_REGION"],
            "access_key": os.environ["CANNER_STORAGE_ACCESS_KEY_ID"],
            "secret_key": os.environ["CANNER_STORAGE_SECRET_ACCESS_KEY"],
            "bucket_name": os.environ["CANNER_STORAGE_BUCKET"],
            "addressing_style": "path",
            "location": "your-project",           # every key starts with the project slug
            "file_overwrite": False,
            "max_memory_size": 5 * 1024 * 1024,   # larger downloads spill to a temp file
        },
    },
    # Defining STORAGES replaces the defaults: keep static files out of the bucket.
    "staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage"},
}

# views.py
from django.contrib.auth.decorators import login_required
from django.http import FileResponse
from django.shortcuts import get_object_or_404

@login_required
def download(request, pk):
    doc = get_object_or_404(Document, pk=pk, owner=request.user)  # 404 for anyone else
    response = FileResponse(doc.file.open("rb"), as_attachment=True, filename=doc.original_name)
    response["Cache-Control"] = "private, no-store"
    return response

# In templates, link to {% url "download" doc.pk %}, never {{ doc.file.url }}.

Rails Active Storage

Active Storage needs one setting on Canner. Its keys are random tokens at the root of the bucket and the S3 service has no prefix option, so it can’t use a folder of the shared bucket: every upload would be refused with AccessDenied. Turn on Own bucket in the project’s storage credentials panel before you create a credential. The project then gets a bucket of its own, and the stock S3 service works as configured below (own buckets). The build log reminds you if a Rails app on S3 hasn’t done this yet.

For downloads, don’t use the built-in URLs. The default redirect mode sends the browser to a presigned URL, which fails here. Proxy mode (config.active_storage.resolve_model_to_route = :rails_storage_proxy) does stream through your app, but Rails warns that those controllers are public to anyone who has the URL, and it marks the response cacheable forever. For private files, write your own controller with ActiveStorage::Streaming, as below. Use a plain form.file_field for uploads, without direct_upload: true.

# config/storage.yml (the project has "Own bucket" on, so Active Storage can use the bucket root)
canner:
  service: S3
  endpoint: <%= ENV["CANNER_STORAGE_ENDPOINT"] %>
  region: <%= ENV["CANNER_STORAGE_REGION"] %>
  access_key_id: <%= ENV["CANNER_STORAGE_ACCESS_KEY_ID"] %>
  secret_access_key: <%= ENV["CANNER_STORAGE_SECRET_ACCESS_KEY"] %>
  bucket: <%= ENV["CANNER_STORAGE_BUCKET"] %>
  force_path_style: true

# config/environments/production.rb
config.active_storage.service = :canner

# app/controllers/documents_controller.rb
class DocumentsController < ApplicationController
  include ActiveStorage::Streaming
  before_action :authenticate_user!

  def show
    document = current_user.documents.find(params[:id]) # someone else's id raises 404
    send_blob_stream document.file.blob, disposition: "attachment"
  end
end

Laravel

Laravel’s s3 driver accepts a root, which prefixes every path on the disk, so store('uploads/1', 'canner') writes your-project/uploads/1/… and returns the path without the prefix. download() streams the object with a Content-Disposition: attachment header. Don’t call Storage::url() or temporaryUrl() for these files: they point at the internal endpoint.

PHP’s own upload_max_filesize and post_max_size still cap what reaches the route, separately from the max: rule.

// config/filesystems.php, under 'disks' (composer require league/flysystem-aws-s3-v3 "^3.0")
'canner' => [
    'driver' => 's3',
    'key' => env('CANNER_STORAGE_ACCESS_KEY_ID'),
    'secret' => env('CANNER_STORAGE_SECRET_ACCESS_KEY'),
    'region' => env('CANNER_STORAGE_REGION'),
    'bucket' => env('CANNER_STORAGE_BUCKET'),
    'endpoint' => env('CANNER_STORAGE_ENDPOINT'),
    'use_path_style_endpoint' => true,
    'root' => 'your-project', // every key starts with the project slug
    'throw' => true,
],

// routes/web.php
Route::middleware('auth')->group(function () {
    Route::post('/files', function (Request $request) {
        $request->validate(['file' => 'required|file|max:20480']); // kilobytes
        $file = $request->file('file');
        $path = $file->store('uploads/'.$request->user()->id, 'canner');
        $doc = $request->user()->documents()->create([
            'path' => $path, 'name' => $file->getClientOriginalName(),
        ]);
        return response()->json(['id' => $doc->id], 201);
    });

    Route::get('/files/{document}', function (Request $request, Document $document) {
        abort_unless($document->user_id === $request->user()->id, 404);
        return Storage::disk('canner')->download(
            $document->path, $document->name, ['Cache-Control' => 'private, no-store']
        );
    });
});

Headers that matter for user files

  • `Content-Disposition: attachment` for anything a user uploaded. Served inline, an uploaded HTML or SVG file runs as a page on your own domain, with your cookies. Serve images inline only if you checked they are images.
  • `X-Content-Type-Options: nosniff` so the browser trusts the type you send rather than guessing from the bytes.
  • `Cache-Control: private, no-store` for anything behind a login. Canner’s optional cache only stores responses marked Cache-Control: public with a positive s-maxage, and never authenticated or Set-Cookie responses, but a cache you put in front yourself might.
  • `404`, not `403`, when the file belongs to someone else, so ids can’t be probed. Use random keys, not the user’s file name.
  • A stored file can disappear. On Canner every object written to storage is scanned with ClamAV within seconds; a match is moved to quarantine and your organization’s admins get an email (virus scan). Treat a missing object as a 404 rather than an error.

Costs and when this isn’t the right fit

Every download goes through your app, so it uses the app’s memory, processor and traffic like any other response (Starter includes 250 GB of traffic a month). Files in the bucket count toward your storage, and deleted or overwritten files are kept 30 days by default so they can be restored (object storage docs).

If you need browsers to upload multi-gigabyte files straight to storage, or public assets served from a bucket behind a CDN, Canner storage doesn’t do that today. Your app on Canner can use an external S3-compatible provider for those files instead. More guides are in hosting by framework.

Questions

Why doesn’t my presigned URL work on Canner?

The storage endpoint is internal to the host your app runs on, so a presigned URL points the browser at 127.0.0.1, its own machine. Serve the file through a route in your app instead.

Why do uploads fail with AccessDenied?

Your credential only allows keys that start with your project’s slug. Add the prefix (location in django-storages, root in Laravel) and check the client uses path-style addressing.

Should private files use signed URLs or go through the app?

On Canner they go through the app. Elsewhere it is a trade-off: a signed URL offloads bandwidth but works for anyone who has it until it expires, while a route checks the user on every request.

Can I use Active Storage direct uploads?

Not with Canner storage: direct uploads send the browser a presigned PUT to the bucket, which it can’t reach. Upload through a normal form so the file passes through your app.

A private bucket next to your app.

Every project gets S3-compatible storage in Montréal, scoped to that project, with deleted files kept for 30 days by default.