mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
Co-authored-by: Merlijn Vos <merlijn@soverin.net> Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') })
|
|
|
|
const express = require('express')
|
|
|
|
const app = express()
|
|
const path = require('node:path')
|
|
|
|
const port = process.env.PORT
|
|
const bodyParser = require('body-parser')
|
|
|
|
const aws = require('aws-sdk')
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
app.get('/', (req, res) => {
|
|
const htmlPath = path.join(__dirname, 'public', 'index.html')
|
|
res.sendFile(htmlPath)
|
|
})
|
|
|
|
app.get('/drag', (req, res) => {
|
|
const htmlPath = path.join(__dirname, 'public', 'drag.html')
|
|
res.sendFile(htmlPath)
|
|
})
|
|
|
|
app.post('/sign-s3', (req, res) => {
|
|
const s3 = new aws.S3()
|
|
const fileName = req.body.filename
|
|
const { contentType } = req.body
|
|
const s3Params = {
|
|
Bucket: process.env.S3_BUCKET,
|
|
Key: fileName,
|
|
Expires: 60,
|
|
ContentType: contentType,
|
|
ACL: 'public-read',
|
|
}
|
|
|
|
s3.getSignedUrl('putObject', s3Params, (err, data) => {
|
|
if (err) {
|
|
console.log(err)
|
|
return res.end()
|
|
}
|
|
const returnData = {
|
|
url: data,
|
|
method: 'PUT',
|
|
}
|
|
res.write(JSON.stringify(returnData))
|
|
res.end()
|
|
})
|
|
})
|
|
|
|
app.listen(port, () => {
|
|
console.log(`Example app listening on port ${port}`)
|
|
})
|