:: krowemoh

Friday | 13 DEC 2024
Posts Links Other About Now

previous
next

File Uploads in Sveltekit Production

2023-04-09

I have a file upload handler that saves files to static/uploads. This works perfectly in dev but when going to production it looks like there are 2 static/uploads and both are different. There is the one that gets packaged into the output directory and that seems to work well enough.

However, the uploads seem to be looking for the one that is right next to the out directory rather than being nested within. I'm not sure what the logic is but it is a pain to sort out.

Ultimately, I created a static/uploads folder next to the out directory that contains the production app. I then expose the uploads folder through nginx and this ties sveltekit and nginx nicely. Uploads are handled by sveltekit and go to the correct upload directory and nginx then serves it out.

This is a weird one because sveltekit is defintely creating a static/uploads folder nested under the production app but then is the expectation that static files are served by sveltekit and not nginx? I'm pretty sure this that the assets under the nested static folder are being served by sveltekit which seems like a mistake.

For now the issue is dealt with but I do need to sort this out. I think the solution going forward should be to have the static folder be an nginx folder that gets served that way and it is excluded from the production process.