W
Wasp5mo ago
JudeJeremy

Where are files stored after being uploaded to the file-upload page?

Sorry if this is a bad question, im just starting out as a web developer
1 Reply
kapa.ai
kapa.ai5mo ago
Hi @JudeJeremy. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- Files uploaded through a file-upload page in a Wasp application are typically not stored on the server itself. As mentioned by a community member in a Discord support thread (https://discord.com/channels/686873244791210014/1210568665347526757), servers on most cloud providers are ephemeral - they get restarted, reset, and you can't count on data on disk being permanent. Instead, files are usually stored on services like S3, Azure blob, or similar. This is also confirmed in a Github issue (https://github.com/wasp-lang/wasp/issues/494) where a contributor mentioned using the @aws-sdk/client-s3 library to store files on S3 or an S3 compatible storage. Here is a code snippet from the Github issue showing how to upload a file to S3:
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,
ContentType: "image/png",
})
);
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,
ContentType: "image/png",
})
);
Please note that the actual storage location might vary depending on the specific setup of your application. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ---------------------- Sorry @JudeJeremy, I seem to be having a bit of trouble. Don't worry though, I've pinged my support and they will try to fix me up! :technologist: Perhaps try again in 15mins?
Want results from more Discord servers?
Add your server