Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/user', (req, res) => {
- const form = formidable({ multiples: true });
- form.parse(req, async (err, fields, files) => {
- if (err) {
- return err;
- }
- const { userID } = fields;
- const { image } = files;
- const user = await User.findById(userID);
- const fileBuffer = Buffer.from(JSON.stringify(image));
- const fileExt = image.originalFilename.split('.')[1];
- const fileMimetype = image.mimetype;
- const params = {
- Bucket: process.env.AWS_BUCKET_NAME,
- Key: `${userID}.${fileExt}`,
- Body: fileBuffer,
- ContentType: fileMimetype,
- ACL: 'public-read',
- };
- s3.upload(params)
- .promise()
- .then((ress) => {
- console.log({ ress });
- })
- .catch((e) => console.log({ err: e }));
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement