Skip to content

Commit 3b4e2c2

Browse files
committed
feat: Add file upload
1 parent 41a8af2 commit 3b4e2c2

File tree

4 files changed

+233
-6
lines changed

4 files changed

+233
-6
lines changed

index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const express = require('express')
2+
const upload = require('./src/attachments')
23
const { validationMiddleware } = require('./src/middlewares')
34
const { PORT } = require('./src/config')
45
const { prepareMailsWithTemplate, parseSettings } = require('./src/pate')
@@ -31,6 +32,18 @@ app.post('*', validationMiddleware, (req, res) => {
3132
res.send('Payload accepted, check logs to see progress')
3233
})
3334

35+
app.post('/upload', upload.single('file'), (req, res) => {
36+
const file = req.file
37+
38+
if (!file) {
39+
return res.status(400).json({ error: 'No file uploaded' })
40+
}
41+
42+
// Respond with the file ID (e.g., filename or path)
43+
const fileId = file.filename
44+
res.json({ fileId })
45+
})
46+
3447
app.listen(PORT, () => {
3548
console.log(`Pate listening at http://localhost:${PORT}`)
3649
})

package-lock.json

Lines changed: 209 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"dependencies": {
1414
"axios": "^0.26.1",
1515
"express": "^4.17.1",
16+
"multer": "^1.4.5-lts.1",
1617
"jest": "^27.0.3",
1718
"mustache": "^4.2.0",
1819
"nodemailer": "^6.6.1",

src/attachments.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import multer from 'multer'
2+
import path from 'path'
3+
4+
// Configure multer for file uploads
5+
const upload = multer({
6+
dest: '/tmp/uploads', // Directory to store uploaded files
7+
limits: { fileSize: 10 * 1024 * 1024 }, // Limit file size to 10MB
8+
})
9+
10+
module.exports = upload

0 commit comments

Comments
 (0)