Next.js Discord

Discord Forum

Download

Answered
Spectacled Caiman posted this in #help-forum
Open in Discord
Avatar
Spectacled CaimanOP
I have an endpoint which downloads the users account information and this can get huge so I don't want to send it over in the request body. How can I download a file on the users PC upon sending an API request. Because in plain nodejs I can just do res.download(filePath);
Answered by Spectacled Caiman
Yeah I decided to zip it and upload it using uploadthing and email the user the download link once it's finished
View full answer

26 Replies

Avatar
risky
where is the data stored...
as if it is in your server, you have to send it in response
Avatar
Spectacled CaimanOP
It's in a db.
Avatar
risky
but as its in a db (because all the user stored), you could upload it to some storage api (like s3 - but don't use s3 as no permissions for security) and give the user a url to download - but it is simpler to just send it as a response...
Avatar
Spectacled CaimanOP
oh that's actually really good.
But the reason that I don't send it over response is that it can easily become 1GB of data
Avatar
risky
idk about other services... but discord sends you an email (can take up to a week after req), and then it sends you an email with a link to download for up to 30 days later
yeah that is a lot... you would def want that as its own zip
Avatar
Spectacled CaimanOP
yeah Spotify does the same
yeah alright so I'll connect it to S3 thanks
Avatar
risky
and is this self hosted or something live vercel?
Avatar
Spectacled CaimanOP
It's gonna be opensourced but also a web version on vercel
Avatar
risky
im not sure how security s3 is and you don't need the benfits of s3 (like edge caching)
Avatar
Spectacled CaimanOP
yea
I may be able to use the blob storage on vercel
Avatar
risky
yeah that is what i was thinking
as you can have "private" data
but how long does it take you to produce said data, like the timeouts on serverless function is only 10sec for base tier(and idk about the max ram usage to make the 1gb file)
Avatar
Spectacled CaimanOP
ohhh shi
I guess ill change the approach and have it accessible in some other way.
I mean i'd still have to use the DB/storage but the way that I setup is gonna be different.
Avatar
risky
yeah that makes sense
Avatar
Spectacled CaimanOP
alright well thanks for everything
Avatar
risky
@Spectacled Caiman just to check, did you end up finding a solution?
Avatar
Spectacled CaimanOP
Yeah I decided to zip it and upload it using uploadthing and email the user the download link once it's finished
Answer
Avatar
risky
Ahh very nice