Search code examples
typescriptnext.jsserverlesstrpc

serve a dynamically generated file from a serverless NextJs application


My NextJs application (t3-stack) runs on Vercel and I use a Planetscale mysql database. It contains a form to collect data and write it into the database. I want to serve the data collected in the form to my users as a csv file. Is there some convenient way - maybe a SaaS - that would allow me to generate that file on the backend upload it somewhere and then return a download link? That download link should only be accessible to that user. Any ideas or recommendations?


Solution

  • I ended up using pre-signed s3 links. More information here I create the file on the backend, upload it s3 and then use the SDK to generate a unique pre-signed link with a limited lifetime. The user can then download. After a day a lifecycle rule deletes the generated object from the bucket.