From ee6bf2603b9fca173b048c9e0cd80b2200654a9e Mon Sep 17 00:00:00 2001 From: Sebastian <sebastian.mihalache@thinslices.com> Date: Tue, 30 Jan 2018 16:09:06 +0200 Subject: [PATCH] fixed uuid bug --- packages/xpub-aws/src/AWSBackend.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/xpub-aws/src/AWSBackend.js b/packages/xpub-aws/src/AWSBackend.js index 4dff7b636..482c5c6a3 100644 --- a/packages/xpub-aws/src/AWSBackend.js +++ b/packages/xpub-aws/src/AWSBackend.js @@ -9,8 +9,8 @@ AWS.config.update({ accessKeyId: process.env.AWS_ACCESS_KEY, region: process.env.AWS_REGION, }) -const fileKey = uuid.v4() const AWSBackend = app => { + app.use(bodyParser.json()) const authBearer = app.locals.passport.authenticate('bearer', { session: false, }) @@ -21,21 +21,28 @@ const AWSBackend = app => { bucket: process.env.AWS_BUCKET, contentType: multerS3.AUTO_CONTENT_TYPE, key: (req, file, cb) => { - // console.log('key cb:', fileKey) - cb(null, fileKey) + cb(null, uuid.v4()) }, }), + // 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( '/api/aws-upload', authBearer, - bodyParser.json(), upload.single('file'), async (req, res) => { // console.log('FILE:', req.file) const params = { Bucket: process.env.AWS_BUCKET, - Key: fileKey, + Key: req.file.key, } s3.getSignedUrl('getObject', params, (err, data) => { @@ -62,7 +69,7 @@ const AWSBackend = app => { res.status(err.statusCode).json({ error: err.message }) return } - res.status(200).json() + res.status(204).json() }) }) } -- GitLab