Skip to content
Snippets Groups Projects
Commit ee6bf260 authored by Sebastian's avatar Sebastian
Browse files

fixed uuid bug

parent f093afe8
No related branches found
No related tags found
No related merge requests found
...@@ -9,8 +9,8 @@ AWS.config.update({ ...@@ -9,8 +9,8 @@ AWS.config.update({
accessKeyId: process.env.AWS_ACCESS_KEY, accessKeyId: process.env.AWS_ACCESS_KEY,
region: process.env.AWS_REGION, region: process.env.AWS_REGION,
}) })
const fileKey = uuid.v4()
const AWSBackend = app => { const AWSBackend = app => {
app.use(bodyParser.json())
const authBearer = app.locals.passport.authenticate('bearer', { const authBearer = app.locals.passport.authenticate('bearer', {
session: false, session: false,
}) })
...@@ -21,21 +21,28 @@ const AWSBackend = app => { ...@@ -21,21 +21,28 @@ const AWSBackend = app => {
bucket: process.env.AWS_BUCKET, bucket: process.env.AWS_BUCKET,
contentType: multerS3.AUTO_CONTENT_TYPE, contentType: multerS3.AUTO_CONTENT_TYPE,
key: (req, file, cb) => { key: (req, file, cb) => {
// console.log('key cb:', fileKey) cb(null, uuid.v4())
cb(null, fileKey)
}, },
}), }),
// fileFilter: (req, file, cb) => {
// console.log('req in fileFilter', req.body.get('fileType'))
// console.log('file in filter:', file)
// if (req.body.fileType === 'supplementary') {
// cb(null, false)
// return
// }
// cb(null, true)
// },
}) })
app.post( app.post(
'/api/aws-upload', '/api/aws-upload',
authBearer, authBearer,
bodyParser.json(),
upload.single('file'), upload.single('file'),
async (req, res) => { async (req, res) => {
// console.log('FILE:', req.file) // console.log('FILE:', req.file)
const params = { const params = {
Bucket: process.env.AWS_BUCKET, Bucket: process.env.AWS_BUCKET,
Key: fileKey, Key: req.file.key,
} }
s3.getSignedUrl('getObject', params, (err, data) => { s3.getSignedUrl('getObject', params, (err, data) => {
...@@ -62,7 +69,7 @@ const AWSBackend = app => { ...@@ -62,7 +69,7 @@ const AWSBackend = app => {
res.status(err.statusCode).json({ error: err.message }) res.status(err.statusCode).json({ error: err.message })
return return
} }
res.status(200).json() res.status(204).json()
}) })
}) })
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment