javascriptnode.jsfile-uploaduploadsveltekit

Image after upload does not exist without restart


I save my image with writeFile but i can't load it in my browser. Except if i restart (npm run dev || node build/index)

await writeFile("static/img/tmp/"+now+".jpg", contentReplace, 'base64');

I use SvelteKit with node-adapter, i don't want to use s3 or anything else because is only for uploading one file the be deleted after an other operation.

I've tried to save my image in many different folders:


Solution

  • The application will only serve files known at build time.
    (You can see the listed files and routes in the build/server/manifest.js.)

    If you want to support uploading/serving of dynamic files you either have to serve the files via its own route that reads the files manually or set up a custom server using the built handler for the regular application logic and some static asset middleware that additionally serves you uploads directory.

    (Given that the files are to be deleted after use, you could also just store the file in memory and serve it from there, then you don't need to deal with the file system at all.)