Next.js Discord

Discord Forum

Can dynamically saved files in public be shown without restarting?

Unanswered
Siamese Crocodile posted this in #help-forum
Open in Discord
Siamese CrocodileOP
I dynamically save files/images into the /public/... folder. However, these images are not made available for the website until a restart is done(no build necessary just simple restart.)

Is there a solution I can do to get around the restart?

9 Replies

Giant panda
That folder is only meant for static files and there is not even a guarantee to have write access to it during runtime. For images like avatars etc. the typical solutions are S3 or R2 buckets to upload them there and reference them then.
Giant panda
Is the app self-hosted or on a cloud provider?
@Giant panda Is the app self-hosted or on a cloud provider?
Siamese CrocodileOP
The client self hosts on a server
Siamese CrocodileOP
@Giant panda Any idea on how to handle dynamically added self-hosted image files to be available through next/image without restarting the website everytime an image is uploaded
@Siamese Crocodile The client self hosts on a server
Use an api route that uses fs to read the file manually and send the file manually as response
@joulev Use an api route that uses fs to read the file manually and send the file manually as response
Greater Pewee
Gee, I didn't think I'd find someone who had the same idea as me xD, I've just started NextJs and I've had the problem that in production you can't see the new images in the public folder. But I thought of some stuff I was doing with Flask in python and came up with this solution.
haha, need to come up with weird solutions when the situation calls for them
to be fair though i think "read the file with fs, then stream/return it" is pretty much what all these frameworks are also doing behind the scenes