Files
inbound-email/services/s3Service.js
T
Martin 39fc7df763 🚀📥
2024-09-19 21:51:50 +08:00

25 lines
640 B
JavaScript

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 };