-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to serve and upload dynamic binary assets (images, pdfs) #494
Comments
Some of the additional conversation we had on this: I had implemented file uploading in the past, in JS / Express / React apps, and you don't really want it to go through your server -> that is a lot of traffic that you rather want to avoid, as it suffocates your server and reduces its capability to do other, more important stuff, like answer user HTTP requests. I guess the first question is, where do you want to store your files? Ideally you would use some file storage, like S3, or a similar offering from other hosting provider. [14:22]
|
Going directly from the client to the storage provider can work for most cases, but not all. What if you are generating files on the server (reports, images etc.) and need to store them? What I did to get it working for my use-case:
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
const S3 = new S3Client({
region: "auto",
endpoint: process.env.R2_BUCKET_URL,
credentials: {
accessKeyId: process.env.R2_ACCESS_TOKEN!,
secretAccessKey: process.env.R2_SECRET_TOKEN!,
},
});
const upload = await S3.send(
new PutObjectCommand({
Bucket: "<bucket_name>",
Key: key,
Body: response.data,
// If uploading images for example
ContentType: "image/png",
})
); |
entjustdoit shared some great info on how he did it, on our Discord: https://discord.com/channels/686873244791210014/1062935979951923280/1088518391494619226 . Here it goes: Sure! First, go to S3 and setup a bucket and IAM user, then add these entries to your .env.server file.
then add the aws sdk to your list of dependencies
In your front end, setup the functions for downloading and uploading files.
|
I think this is a great candidate for potential Full Stack Modules. |
Wasp currently has no way to let users download dynamic binary assets nor upload them. This is a fairly common use case, so should be supported. Where these assets are stored is a related topic (database, s3, etc)
The text was updated successfully, but these errors were encountered: