Next.js Discord

Discord Forum

Temporary Files in /public

Answered
Tonkinese posted this in #help-forum
Open in Discord
Avatar
TonkineseOP
Hey,

Is there any way storing temporary files in public? And serving them to customers?
I know that they get lost on new deployments, they are just temporary for like 1 minute.
Answered by Rafael Almeida
no, if you want to serve an asset from the /public folder it should exist during build time. for runtime file uploading you need to upload it to another service
View full answer

14 Replies

Avatar
@Tonkinese Hey, Is there any way storing temporary files in public? And serving them to customers? I know that they get lost on new deployments, they are just temporary for like 1 minute.
Avatar
no, if you want to serve an asset from the /public folder it should exist during build time. for runtime file uploading you need to upload it to another service
Answer
Avatar
@Rafael Almeida no, if you want to serve an asset from the `/public` folder it should exist during build time. for runtime file uploading you need to upload it to another service
Avatar
TonkineseOP
:mhm: Okay sure. Yeah I was planing on hosting a socketio server with next and then generate some TextToSpeech MP3 and play it from the public.

But I guess socketio server isnt even supported with nextjs so
But appreciate you
Avatar
@Rafael Almeida no, if you want to serve an asset from the `/public` folder it should exist during build time. for runtime file uploading you need to upload it to another service
Avatar
TonkineseOP
Tried the official docs for nextjs & socket io but that wasnt working. I really need access to the io, but i cant export io because of next.

And then in combination with that issue
Image
It tells me that I cant export io when in the same file is the const app = next({dev, hostname, port})
Any Idea how i can avoid that?
Avatar
this requires a custom server which is not really recommended. if you want a socket server its better to build it externally from the next.js server
Avatar
TonkineseOP
So then it would be better to have the Socket IO and TTS generator seperatly as a microservice for example as docker and then provide the Mp3 URL to the client in nextjs with all required data?
And for everything else where I need to update data I also could fetch an api endpoint every 3 seconds?
Like If i need to display

Title: This is a Title
Rating: 5/5

And then when i need the new data make a api request where i get json?
I guess so
Avatar
@Rafael Almeida no, if you want to serve an asset from the `/public` folder it should exist during build time. for runtime file uploading you need to upload it to another service
Avatar
TonkineseOP
Sad that this is not possible, but i guess express does support this. So should be easy to get a microservice working for that!
Avatar
@Tonkinese So then it would be better to have the Socket IO and TTS generator seperatly as a microservice for example as docker and then provide the Mp3 URL to the client in nextjs with all required data?
Avatar
yeah probably. I don't really understand the other stuff you are saying, but the idea is if you have a long-running service (like sockets) you need to separate it
Avatar
TonkineseOP
Okay great to know. Thank you so much for helping!