Skip to content

Remove temp file when file is successfully uploaded - #167

Closed
aaronofinn wants to merge 1 commit into
fastify:mainfrom
aaronofinn:fix/orphaned-temp-file-on-reupload
Closed

aaronofinn wants to merge 1 commit into
fastify:mainfrom
aaronofinn:fix/orphaned-temp-file-on-reupload

Conversation

@aaronofinn

Copy link
Copy Markdown
Contributor

When uploading a file for a task that already has a file, it moves the old file to a temp directory. But on a successful upload, the temporary file still stays there so this is just a small fix to remove that temp file when the operation is successful.

How to reproduce (before this fix)

curl -c /tmp/c.txt -X POST http://localhost:3000/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{"email":"basic@example.com","password":"Password123$"}'

# upload once
curl -b /tmp/c.txt -X POST http://localhost:3000/api/tasks/1/upload -F "file=@/path/to/image.png"
# upload again onto the same task
curl -b /tmp/c.txt -X POST http://localhost:3000/api/tasks/1/upload -F "file=@/path/to/image.png"

ls uploads/tasks/temp/
# a leftover temp-<random>-1_image.png sits here after the second upload succeeded

Checklist

@sonarqubecloud

Copy link
Copy Markdown

@jean-michelet

jean-michelet commented Sep 14, 2026 •

Copy link
Copy Markdown
Member

I think we should remove this feature of file upload, I tried to do this to illustrate the use of the multipart plugin and streams usage, but there are several system design flaws that fixing theme would make to much noise for a basic demo.

@aaronofinn aaronofinn closed this Sep 14, 2026
@aaronofinn
aaronofinn deleted the fix/orphaned-temp-file-on-reupload branch September 14, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants