Strapi Uploads Gone After Redeploy? Restore and Keep Them
Recover Strapi uploads that return 404 after a redeploy. Compare files across releases, resolve conflicting copies, and keep uploads in one shared folder.
When Strapi uploads disappear after a redeploy, the Media Library still lists each file, but its URL under /uploads/ answers 404. Strapi's default upload provider writes every file into public/uploads inside the app's own folder, and the database keeps only a record that points at it. A deploy that builds a fresh folder, or cleans or syncs the old one, starts public/uploads empty again while the records stay. The files are often still on the server, in an older release's folder. This post shows how to check that, merge them into one shared folder without overwriting a newer copy, link that folder in every later release, and roll back without losing it. It covers Strapi running directly on one server, with no containers.
How it was tested: the lab at the end is a fixture with no Strapi in it. You can run it as an ordinary user in a few seconds, and it checks every status and every byte it serves, so it stops with an error if a step does not do what this post says. Separately, on 2026-12-02 I ran Strapi 5.65.0, then the newest release on npm, in production mode on 127.0.0.1 with SQLite outside the releases. The outputs marked "real Strapi" come from that one run. It did not test a rollback, a replaced file, sudo or systemd, and the helper that ran it is retired, since it put a throwaway password on the command line. I build ox, which deploys apps with one folder per release. You need no ox for any of this.
Why the files disappear
Strapi's media library docs say the default provider "uploads files to a local public/uploads/ directory in your Strapi project". In the provider's 5.65.0 source, that folder is uploads inside Strapi's public folder, which is ./public under the app unless dirs.public moves it. Each file is saved as its name, an underscore, ten random hex characters and its extension, and its URL is /uploads/ plus that name. For an image in a format Strapi can resize, it also saves a thumbnail_ copy when the image is bigger than the thumbnail. With the responsive setting on, which a new project has, it adds a small_, medium_ or large_ copy only for each of those sizes that the image's width or height exceeds, so a small image gets fewer copies. The real run below made only thumbnail_ and small_. Each record lists the copies it has in its formats field. The upload plugin serves /uploads/ from the public folder, and in 5.65.0 the strapi::public middleware, which a new project's config/middlewares.js turns on, serves every other file in the public folder to anyone, with no sign-in.
The record of each file, with its URL, goes to the database, in the files table. A new project's .gitignore leaves the files out of git (public/uploads/*) and keeps an empty .gitkeep, so a fresh checkout has the folder and nothing in it.
Three ways a deploy empties the folder:
- A new folder per release. The deploy checks out the code into a new folder, builds it there and points
currentat it. The newpublic/uploadsholds only.gitkeep. The files stay in the old release's folder until the tool prunes it. git clean -fdxin place. The-xoption drops the ignore rules, so the ignored uploads are deleted too. In a test repo,git clean -fdwithout-xleft them alone.rsync --deletefrom a checkout.--deleteremoves files on the server that the source lacks, and a CI checkout has no uploads.
This is the real Strapi run, with one folder per release. It uploaded an image, deployed a second release, and asked for each URL:
live: r1
200 /uploads/hero_035f5e9958.png
200 /uploads/thumbnail_hero_035f5e9958.png
200 /uploads/small_hero_035f5e9958.png
live: r2
404 /uploads/hero_035f5e9958.png
404 /uploads/thumbnail_hero_035f5e9958.png
404 /uploads/small_hero_035f5e9958.png
media library records: 1 ['/uploads/hero_035f5e9958.png']
The record survived, the files did not, and all three files were still in releases/r1/public/uploads.
One more detail decides how you restore. When an editor uses Replace on a file in the Media Library, Strapi 5.65.0 keeps the file's name, so its URL does not change (the upload service's replace keeps the old hash and extension). If that happened after a redeploy, the old release and the new one hold different images under the same name, and the newer one is the one the editor wants. A plain copy of every release into one folder lets whichever copy runs last win.
If the Media Library is empty as well, and your content is gone too, one likely cause is that the app opened a different database. Check 3 below shows which database file the running process holds. The project template's config/database.js puts SQLite at .tmp/data.db inside the app folder unless DATABASE_CLIENT or DATABASE_FILENAME says otherwise, and .tmp is in the same .gitignore, so a new release starts a new, empty database. The old one may still be in the old release's folder.
Check a running server
These checks only read. The service name strapi, the host and the paths are examples. Use your own.
1. Ask the public URL, then Strapi itself. Copy an image URL from the Media Library:
curl -sS -o /dev/null -w '%{http_code}\n' https://cms.example.com/uploads/hero_035f5e9958.png
curl -sS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:1337/uploads/hero_035f5e9958.png
1337 is the template's default port. A 404 from both, with the file still listed in the Media Library, fits this problem, but it does not prove it yet: the next two checks do. A 200 from Strapi and a 404 from the public URL suggests your proxy instead.
2. Confirm the provider and the public folder. Strapi merges config/env/<NODE_ENV>/ over config/, so read both plugins.js files (or .ts; a TypeScript app loads them from dist/config) for the NODE_ENV your service sets. Each record in the files table also has a provider column with the provider that stored it, local for the default one. If the setting or the records name another provider, such as S3 or Cloudinary, this post does not apply. Look for dirs.public in both server.js files too. If it is set, use that folder wherever this post says public.
3. Find the folder and the database the running Strapi uses. When npm or a shell script starts Strapi, systemd's main process is that launcher and not Node, so ask every process in the service. A process's working folder is shown with every link resolved, so it names the real release, as long as Strapi starts from the app folder, as systemd's WorkingDirectory usually sets it:
cg=$(systemctl show -p ControlGroup --value strapi)
for pid in $(cat "/sys/fs/cgroup$cg/cgroup.procs"); do
echo "$pid $(cat /proc/$pid/comm) $(sudo readlink /proc/$pid/cwd)"
sudo ls -l /proc/$pid/fd | grep '\.db'
done
Each process prints its name and the release it runs in. The node line names the release, and below it any .db file it holds open, which, if you use SQLite, should be the database you expect. For another database, compare config/database.js and its config/env copy with what you expect. Then list that release's public/uploads: is it a link, and does it hold more than .gitkeep?
4. Find where the file went. Search the folders that hold your releases, your backups, and anything public/uploads ever linked to. findmnt lists other disks mounted there.
sudo find /srv/strapi -name 'hero_035f5e9958.png'
A hit in an older release's public/uploads means you can get it back with the next section. With no hit anywhere, only a backup or a fresh upload brings the file back.
Get the files back
Do this before your next deploy, because many deploy tools delete their oldest release folders. Plan a short maintenance window: the steps are only safe while nothing can write media. Use the folders your checks found, not the example paths.
- Stop every writer. Pause deploys and release pruning. Stop every Strapi process that uses this database, on every server, and anything else that uploads, replaces or deletes media through it. Check that each one is gone and that nothing listens on Strapi's port. An upload, a Replace or a delete that lands after the next step would be lost or served stale.
- Take the inventory. From the database, list the
urlof every row in thefilestable whoseproviderislocal, plus everyurlinside that row'sformats, which are the exact size copies Strapi made. Save the list. A name the table no longer lists was deleted in the Media Library, so leave it out: copying it back would make its old URL answer 200 again. - Stage a copy. In a new folder that nothing serves, such as
/srv/strapi/shared/uploads.new, copy each listed name from the release folder you select. Record every candidate path and checksum for that name, including identical copies, and mark which one you selected. Stop if a listed name is in no release: bring it back from a backup, or decide that it is lost and its URL will answer 404. Stop if two releases hold different bytes under one name, and choose one, usually the newer release, where an editor's Replace landed. Do not let a copy loop decide. - Check again, then switch. With the writers still stopped, take the inventory again and compare it with the saved one, then enumerate every candidate path again. Compare the full set of paths and checksums with the first pass, including copies in releases you did not select. Verify each staged file against its selected checksum. If anything changed, leave the releases untouched, identify the writer and restart with fresh staging. These comparisons require a verified write freeze through cutover. Then rename the staging folder to
shared/uploads, which must not exist yet. For each release, check that itspublicis a real folder inside that release, not a link into another tree. Move the release's ownpublic/uploadswithmv -Tto a new folder outside everything Strapi and your web server serve, such as/srv/strapi/recovery/<release>/uploads, and put a link to the shared folder in its place. - Lock the originals away. Give the recovery folder to an admin only (
chmod 700) and make its files read-only. Never keep these copies underpublic. Thestrapi::publicmiddleware would serve them under a second URL, deleted and replaced files included. - Start Strapi and verify. For every recovered URL, compare the response bytes with the staged checksum. For each file explicitly accepted as lost, verify that its URL returns 404. Request a deleted file's old URL, and the path where an old copy would sit in
public, and expect 404 from both. Only then let writers back.
Every step needs a user that can write to the release folders and the shared folder, and the shared folder must belong to the user that runs Strapi, so new uploads can land there. Check there is room for one more copy of the uploads first. If the site is wrong after the start, stop Strapi, remove each release's link, move its folder back from recovery/<release>/uploads and start it again. Keep the recovery folders until you have checked the site and a backup holds the shared folder.
Keep them on every later deploy
Your deploy must link the folder in each new release after the build and before the switch, and stop the deploy if it cannot. Before it touches anything, it should check that the release is a new, inactive release folder, that the release's public and public/uploads are real folders and not links into another tree, that public/uploads holds nothing but .gitkeep, and that the shared folder exists. Remove the verified scaffold file .gitkeep if present. Then remove the empty folder with rmdir, which fails on anything left inside, never with a recursive delete. The lab shows each refusal.
In the real Strapi run, the folder was linked in two new releases. An image uploaded in the first landed in the shared folder, and after the next deploy the files of both uploads answered 200:
live: r4
200 /uploads/hero_035f5e9958.png
200 /uploads/thumbnail_hero_035f5e9958.png
200 /uploads/small_hero_035f5e9958.png
200 /uploads/team_5180017d9a.png
200 /uploads/thumbnail_team_5180017d9a.png
media library records: 2 ['/uploads/hero_035f5e9958.png', '/uploads/team_5180017d9a.png']
Make the shared folder before the first deploy that links it. The provider checks the folder when Strapi loads it and throws if it is missing. With the link leading nowhere, the run printed:
The upload folder ($B/releases/r4/public/uploads) doesn't exist or is not accessible. Please make sure it exists.
If you deploy in place instead, keep the folder out of what the deploy cleans: drop -x from git clean, or exclude the folder from rsync --delete. With the project folder as the transfer root (a source path ending in /), --exclude /public/uploads/ kept the files in a test. Run it once with --dry-run and read what it would delete. To keep no files on the server at all, Strapi's other providers upload to a service such as Amazon S3 or Cloudinary.
The shared folder is now the only copy, so back it up with the database (automate PostgreSQL backups on a VPS covers the database side).
Roll back without losing them
A rollback points current at an older release folder. If that folder still has its own public/uploads, the rollback serves that release's old copy, which is why the restore links every release, not only the live one. In the lab, a rollback to the first release served every inventoried file with its newest bytes, and the two deleted files answered 404 both at /uploads/ and where an old copy would sit in public, because their only copies are in the private recovery folder.
That result is about files only. A rollback keeps the database you have now when it lives outside the releases. Older Strapi code can still change the schema when it starts, and a SQLite file inside a release changes with the switch. Check the rollback notes of the versions you move between.
Reproduce it with a fixture
This lab is a fixture, not Strapi, and not a deploy tool. Python's built-in web server stands in for Strapi serving public/, and a text file stands in for the names the files table lists. It shows how the folders and the links behave, and it checks every answer: each status, the bytes of each file, that each refused step changed nothing, that each release's own uploads survive unchanged, read-only and unserved, and that its own process holds the port. Any miss stops it with FAIL: and a non-zero exit. It runs as your ordinary user, on 127.0.0.1 port 8137 only. Every function takes a release name and works only inside the one new folder it makes under /tmp, which it removes when it ends, even on an error. You need bash, python3, curl, ss and the usual GNU tools.
Save it as strapi-uploads-lab.sh and run bash strapi-uploads-lab.sh:
#!/usr/bin/env bash
# A fixture, not Strapi and not a deploy tool: python3's web server stands in
# for Strapi serving public/, records.txt for the names the files table lists.
# Ordinary user, 127.0.0.1 only. Every function takes a release name and works
# only inside the one new temp folder it makes, which it removes at the end.
set -euo pipefail
PORT=8137 SRV= LAB=
fail() { echo "FAIL: $*" >&2; exit 1; }
stop() { if [ -n "$SRV" ]; then kill "$SRV"; wait "$SRV" 2>/dev/null || true; SRV=; fi; }
cleanup() { stop; case $LAB in /tmp/strapi-uploads-lab.??????) rm -rf -- "$LAB" ;; esac; }
trap cleanup EXIT
start() { # serve the live release, and prove our own process holds the port
stop
python3 -m http.server --bind 127.0.0.1 --directory "$(readlink -f "$LAB/current")/public" "$PORT" >/dev/null 2>&1 &
SRV=$!
for _ in $(seq 50); do
if ss -ltnpH "sport = :$PORT" | grep -q "pid=$SRV,"; then return 0; fi
sleep 0.1
done
fail "our server is not the one listening on port $PORT"
}
switch() { ln -sfn -- "releases/$1" "$LAB/current.new"; mv -T -- "$LAB/current.new" "$LAB/current"; start; echo "live: $1"; }
build() { cp -a -- "$LAB/repo" "$LAB/releases/$1"; }
upload() { printf '%s\n' "$2" > "$LAB/current/public/uploads/$1"; grep -qxF -- "$1" "$LAB/records.txt" || echo "$1" >> "$LAB/records.txt"; }
forget() { grep -vxF -- "$1" "$LAB/records.txt" > "$LAB/tmp/rec" || true; cp -- "$LAB/tmp/rec" "$LAB/records.txt"; }
expect() { # expect CODE PATH [TEXT]: the status, and with TEXT the exact bytes
local got
got=$(curl -s -o "$LAB/tmp/body" -w '%{http_code}' "http://127.0.0.1:$PORT/$2") || true
[ "$got" = "$1" ] || fail "/$2 answered $got, wanted $1"
if [ $# -eq 3 ]; then printf '%s\n' "$3" | cmp -s - "$LAB/tmp/body" || fail "/$2 served other bytes"; fi
echo "$got /$2${3:+ ($3)}"
}
hidden() { expect 404 "uploads/$1"; expect 404 "uploads.before-shared/$1"; }
tree() { (cd "$LAB" && find . -path ./tmp -prune -o -printf '%p %y %l\n' | sort && find . -path ./tmp -prune -o -type f -exec sha256sum {} + | sort) | sha256sum; }
refuses() { # refuses WHY CMD...: CMD must fail, say WHY, and change nothing
local why=$1 rc=0 before; shift
before=$(tree)
( "$@" ) 2>"$LAB/tmp/err" & wait $! || rc=$?
[ "$rc" != 0 ] || fail "$* did not refuse"
grep -q -- "$why" "$LAB/tmp/err" || fail "$* failed another way: $(cat "$LAB/tmp/err")"
[ "$(tree)" = "$before" ] || fail "$* changed files before refusing"
sed "s|^FAIL: ||; s|$LAB|\$LAB|g; s|^|refused: |" "$LAB/tmp/err"
}
frozen() { [ -z "$SRV" ] || fail "stop the app first"; }
plain_public() { # the release's public must be its own folder, not a link elsewhere
[ -d "$1/public" ] && [ ! -L "$1/public" ] && [ -d "$1/public/uploads" ] && [ ! -L "$1/public/uploads" ] || fail "${1##*/}/public is not a plain folder"
}
stage() { # stage [NAME=RELEASE|NAME=lost...]: with writers stopped, copy every listed name
local s=$LAB/shared name pick a r hits bad=
frozen
[ ! -e "$s" ] || fail "something is staged already"
mkdir -p -- "$s/uploads.new"; cp -- "$LAB/records.txt" "$s/inventory"; : > "$s/manifest"
while read -r name; do
pick=; hits=
for a in "$@"; do if [ "${a%%=*}" = "$name" ]; then pick=${a#*=}; fi; done
if [ "$pick" = lost ]; then echo "accepted as lost: $name"; continue; fi
for r in "$LAB"/releases/*; do
if [ -f "$r/public/uploads/$name" ] && { [ -z "$pick" ] || [ "${r##*/}" = "$pick" ]; }; then hits="$hits ${r##*/}"; fi
done
for r in $hits; do
if [ ! -e "$s/uploads.new/$name" ]; then cp -p -- "$LAB/releases/$r/public/uploads/$name" "$s/uploads.new/$name"; echo "$name $r" >> "$s/manifest"
elif ! cmp -s -- "$LAB/releases/$r/public/uploads/$name" "$s/uploads.new/$name"; then echo "conflict: $name differs between releases" >&2; bad=1; fi
done
[ -n "$hits" ] || { echo "missing: $name is in no release" >&2; bad=1; }
done < "$LAB/records.txt"
if [ -n "$bad" ]; then rm -rf -- "$s"; fail "nothing staged: choose a copy, or accept a file as lost"; fi
echo "staged: $(ls "$s/uploads.new" | paste -sd ' ')"
}
unstage() { [ ! -e "$LAB/shared/uploads" ] || fail "already cut over"; rm -rf -- "$LAB/shared"; }
cutover() { # with writers stopped: recheck, keep each release's own folder private, link
local name r
frozen
[ -d "$LAB/shared/uploads.new" ] && [ ! -e "$LAB/shared/uploads" ] && [ ! -e "$LAB/recovery" ] || fail "nothing staged"
cmp -s -- "$LAB/records.txt" "$LAB/shared/inventory" || fail "inventory changed since staging"
while read -r name r; do
cmp -s -- "$LAB/releases/$r/public/uploads/$name" "$LAB/shared/uploads.new/$name" || fail "$name changed since staging"
done < "$LAB/shared/manifest"
for r in "$LAB"/releases/*; do plain_public "$r"; done
mv -T -- "$LAB/shared/uploads.new" "$LAB/shared/uploads"
mkdir -m 700 -- "$LAB/recovery"
for r in "$LAB"/releases/*; do
mkdir -- "$LAB/recovery/${r##*/}"
mv -T -- "$r/public/uploads" "$LAB/recovery/${r##*/}/uploads"
ln -s -- "$LAB/shared/uploads" "$r/public/uploads"
done
find "$LAB/recovery" -type f -exec chmod a-w {} +
echo "cut over: $(ls "$LAB/recovery" | paste -sd ' '), originals in \$LAB/recovery"
}
link_uploads() { # link_uploads RELEASE: a fresh, inactive release only
local rel up
case ${1-} in r[0-9]|r[0-9][0-9]) ;; *) fail "'${1-}' is not a release name" ;; esac
rel=$LAB/releases/$1 up=$LAB/releases/$1/public/uploads
[ -d "$rel" ] && [ ! -L "$rel" ] || fail "$1 is not a release"
[ "$(readlink -f -- "$rel")" != "$(readlink -f -- "$LAB/current")" ] || fail "$1 is live"
[ -d "$LAB/shared/uploads" ] && [ ! -L "$LAB/shared/uploads" ] || fail "no shared uploads folder"
plain_public "$rel"
[ -z "$(find "$up" -mindepth 1 ! -name .gitkeep -print -quit)" ] || fail "$1/public/uploads holds more than .gitkeep"
rm -f -- "$up/.gitkeep"
rmdir -- "$up"
ln -s -- "$LAB/shared/uploads" "$up"
}
if ss -ltnH "sport = :$PORT" | grep -q .; then fail "port $PORT is taken"; fi
LAB=$(mktemp -d /tmp/strapi-uploads-lab.XXXXXX)
mkdir -p "$LAB/repo/public/uploads" "$LAB/releases" "$LAB/tmp"
touch "$LAB/repo/public/uploads/.gitkeep" "$LAB/records.txt"
echo "== 1. upload, redeploy, replace one file, delete one, lose one"
build r1; switch r1
upload hero_a1.png 'hero v1'; upload old_b2.png 'old'; upload lost_e5.png 'lost'
expect 200 uploads/hero_a1.png 'hero v1'
build r2; switch r2
expect 404 uploads/hero_a1.png
upload hero_a1.png 'hero v2'; upload logo_c3.png 'logo'; forget old_b2.png
rm -- "$LAB/releases/r1/public/uploads/lost_e5.png" # its only copy is gone
echo "== 2. stop every writer, then stage the inventory"
refuses 'stop the app first' stage
stop
refuses 'differs between releases' stage
refuses 'is in no release' stage hero_a1.png=r2
stage hero_a1.png=r2 lost_e5.png=lost
echo "-- a writer that was not stopped adds one file and deletes one"
upload late_f6.png 'late'; forget logo_c3.png
refuses 'inventory changed' cutover
unstage; stage hero_a1.png=r2 lost_e5.png=lost
echo "-- a writer that was not stopped replaces a file under the same name"
printf 'hero v3\n' > "$LAB/releases/r2/public/uploads/hero_a1.png"
refuses 'changed since staging' cutover
unstage; stage lost_e5.png=lost hero_a1.png=r2
echo "== 3. cut over, start, check what is served"
(cd "$LAB/releases" && find . -path '*/public/uploads/*' -type f -print0 | sort -z | xargs -0 sha256sum | sed 's|/public/uploads/|/uploads/|') > "$LAB/tmp/before"
cutover; start
expect 200 uploads/hero_a1.png 'hero v3'; expect 200 uploads/late_f6.png 'late'; expect 404 uploads/lost_e5.png
hidden logo_c3.png; hidden old_b2.png
echo "== 4. a new release is linked before its switch, or refused"
build r3
refuses 'is not a release name' link_uploads ../repo
refuses 'is live' link_uploads r2
touch "$LAB/releases/r3/public/uploads/stray.png"
refuses 'more than .gitkeep' link_uploads r3
rm -- "$LAB/releases/r3/public/uploads/stray.png"
mkdir "$LAB/other"; mv -T -- "$LAB/releases/r3/public" "$LAB/other/public"; ln -s -- "$LAB/other/public" "$LAB/releases/r3/public"
refuses 'not a plain folder' link_uploads r3
rm -- "$LAB/releases/r3/public"; mv -T -- "$LAB/other/public" "$LAB/releases/r3/public"; rmdir -- "$LAB/other"
mv -T -- "$LAB/shared/uploads" "$LAB/shared/uploads.away"
refuses 'no shared uploads folder' link_uploads r3
mv -T -- "$LAB/shared/uploads.away" "$LAB/shared/uploads"
link_uploads r3; switch r3
upload team_d4.png 'team'
expect 200 uploads/hero_a1.png 'hero v3'; expect 200 uploads/team_d4.png 'team'
echo "== 5. roll back to the first release"
switch r1
expect 200 uploads/hero_a1.png 'hero v3'; expect 200 uploads/late_f6.png 'late'; expect 200 uploads/team_d4.png 'team'
hidden logo_c3.png; hidden old_b2.png
(cd "$LAB/recovery" && find . -type f -print0 | sort -z | xargs -0 sha256sum) | cmp -s - "$LAB/tmp/before" || fail "a release's own uploads changed"
[ "$(stat -c %a "$LAB/recovery")" = 700 ] && [ -z "$(find "$LAB/recovery" -type f -perm /222)" ] || fail "recovery copies are not private and read-only"
echo "each release's own uploads are unchanged, read-only, in a mode 700 folder"
echo "== 6. clean up"
stop; L=$LAB; cleanup; LAB=
[ ! -e "$L" ] || fail "$L is still there"
if ss -ltnH "sport = :$PORT" | grep -q .; then fail "port $PORT is still in use"; fi
echo "lab folder removed, port $PORT free"
Its output:
== 1. upload, redeploy, replace one file, delete one, lose one
live: r1
200 /uploads/hero_a1.png (hero v1)
live: r2
404 /uploads/hero_a1.png
== 2. stop every writer, then stage the inventory
refused: stop the app first
refused: conflict: hero_a1.png differs between releases
refused: missing: lost_e5.png is in no release
refused: nothing staged: choose a copy, or accept a file as lost
refused: missing: lost_e5.png is in no release
refused: nothing staged: choose a copy, or accept a file as lost
accepted as lost: lost_e5.png
staged: hero_a1.png logo_c3.png
-- a writer that was not stopped adds one file and deletes one
refused: inventory changed since staging
accepted as lost: lost_e5.png
staged: hero_a1.png late_f6.png
-- a writer that was not stopped replaces a file under the same name
refused: hero_a1.png changed since staging
accepted as lost: lost_e5.png
staged: hero_a1.png late_f6.png
== 3. cut over, start, check what is served
cut over: r1 r2, originals in $LAB/recovery
200 /uploads/hero_a1.png (hero v3)
200 /uploads/late_f6.png (late)
404 /uploads/lost_e5.png
404 /uploads/logo_c3.png
404 /uploads.before-shared/logo_c3.png
404 /uploads/old_b2.png
404 /uploads.before-shared/old_b2.png
== 4. a new release is linked before its switch, or refused
refused: '../repo' is not a release name
refused: r2 is live
refused: r3/public/uploads holds more than .gitkeep
refused: r3/public is not a plain folder
refused: no shared uploads folder
live: r3
200 /uploads/hero_a1.png (hero v3)
200 /uploads/team_d4.png (team)
== 5. roll back to the first release
live: r1
200 /uploads/hero_a1.png (hero v3)
200 /uploads/late_f6.png (late)
200 /uploads/team_d4.png (team)
404 /uploads/logo_c3.png
404 /uploads.before-shared/logo_c3.png
404 /uploads/old_b2.png
404 /uploads.before-shared/old_b2.png
each release's own uploads are unchanged, read-only, in a mode 700 folder
== 6. clean up
lab folder removed, port 8137 free
Step 1 is the failure, plus a Replace, a delete and a file whose only copy is gone. Step 2 refuses to stage while the app runs, then refuses the conflict and the missing file until each has a decision. The fixture detects a changed inventory and a replacement in the selected source after staging. It does not detect a replacement confined to an unselected duplicate. On a server, keep every writer stopped and recheck all candidate copies as described above. Step 3 switches and checks that the deleted files are served nowhere. Step 4 refuses unsafe new releases, including one whose public leads into another tree, which it leaves byte for byte as it was. Step 5 rolls back. Do the real restore by hand with the steps above. The fixture uses the specific cases shown in its output.
How ox keeps a folder across deploys
For the release switch itself, see how a new release takes over traffic. On ox, you name the folder in ox.toml:
[storage]
keep = ["public/uploads"]
Each deploy then replaces public/uploads in the new release, after the build, with a link to the same path under the project's data folder (OX_DATA_DIR), as the project's own user. Files the release ships there, such as .gitkeep, are copied in only under names the data folder lacks, so a kept file is never replaced by the repo. On the first deploy with the line, if the app wrote uploads into its live release, ox stops the live app once and carries those files into the data folder. When the data folder already holds a different file under the same name, ox first moves that one aside to <name>.ox-before-<release> and logs the name. That superseded copy sits beside the kept upload. Strapi can serve it publicly at its new URL. Keep public access blocked throughout the first carry. As the project user, move each conflict copy to private storage outside all served directories, verify its contents there and confirm its former URL returns 404 at the origin before reopening access. ox reads only the live release, so files left in older releases are not carried. I have not tested importing those into ox's data folder, and I have not yet run Strapi itself through ox's test suite. The config reference has the details.
Key takeaways
- Strapi's default provider writes uploads into
public/uploadsinside the app folder, and the database keeps only the record and URL. - A deploy that builds a new folder, runs
git clean -fdx, or runsrsync --deletefrom a checkout empties that folder and leaves the records, so their URLs answer 404. - Look in the older release folders first: the files are often still there, until the deploy tool prunes them.
- Stop every writer first, stage only the exact URLs the records list, refuse a missing file or two different files with one name, and link the merged folder in every release.
- Keep each release's old folder read-only in a private place outside
public, never beside the link. - Link it in every new release before the switch, refuse when anything looks wrong, and back up the shared folder.
Frequently asked questions
Why do my Strapi images return 404 after a deploy?
The default provider saves each file in public/uploads inside the app's folder and keeps its record in the database. A deploy that starts from a fresh checkout, or cleans or syncs the folder, leaves that folder empty while the records stay, so the Media Library lists files whose URLs answer 404.
Can public/uploads be a symlink in Strapi?
Yes. In one run of Strapi 5.65.0, with public/uploads a link to a folder outside the release, uploads were written into that folder and served with status 200, including the thumbnails Strapi made. The folder must exist when Strapi starts: the upload provider throws an error saying the upload folder does not exist.
Why did my content disappear along with the uploads?
Check whether the app opened a different database. The project template stores SQLite at .tmp/data.db inside the app folder unless DATABASE_CLIENT or DATABASE_FILENAME says otherwise, so a fresh release starts a new, empty database. Look for the old .tmp/data.db in a previous release folder, and keep the database outside the releases.
Next step
Run the lab once to see each check fail and pass, then run the four checks against one broken image on your server before the next deploy prunes an old release.
New to running apps on your own server? How ox runs your apps shows what ox sets up on your server.
