This commit is contained in:
Martin
2024-09-19 21:51:50 +08:00
commit 39fc7df763
10 changed files with 2788 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
const config = require('../config');
async function uploadToS3(attachment) {
if (attachment.size > config.MAX_FILE_SIZE) {
console.log(`Skipping large attachment: ${attachment.filename} (${attachment.size} bytes)`);
return null;
}
const params = {
Bucket: config.BUCKET_NAME,
Key: `${Date.now()}-${attachment.filename}`,
Body: attachment.content,
ContentType: attachment.contentType
};
try {
const result = await config.s3.upload(params).promise();
return result.Location;
} catch (error) {
console.error('S3 upload error:', error);
throw error;
}
}
module.exports = { uploadToS3 };