Support Forums

[Question] How long can files survive in /tmp for a netlify function?

I am planning to use a netlify function to create some (multiple) temporary files on request, and respond with a 201 created, so that user/frontend can use (process or download) those files later.

It should usually be within seconds or minutes after the 201 response. However I am not sure whether they can survive that long.

Is it doable like this or should I do it in some other ways ?

Hey @yw662 :wave:t2:

I’d strongly advise against this, and for all the experience I have, this won’t work. Once a function returns, there’s no further processing you can do in that runtime instance, nor do I believe there’s a way to access any files you may have accessed, referenced, or created within that function’s context externally.

Is there any way you can instead leverage Netlify’s background functions to generate the files in real time and send them back in the response?


Thanks for your information @jonsully.

This problem is that, I have multiple files to send, and each of them is about 1MB, so I definitely don’t want base64 (which means larger latency and 1/3 more data usage).

Another problem is that some files might need to be sent back for further process, if they are not stored somewhere.

How would you recommend me to do these ?

I’d recommend using a third party service that exclusively handles file storage — AWS S3 for example. Your function could dump files there then return the URLs to exactly those files for direct download.


1 Like