const upload = audioStream => s3 .upload({ ACL: "public-read", ContentType: "audio/mp3", Bucket: process.env.TRANSCRIPTS_BUCKET, Key: uuid(), Body: audioStream, StorageClass: "REDUCED_REDUNDANCY" }) .promise() .then(data => data.Location)
const updateProfileImage = async (file, userId) => { try { const imageFile = await uploadImageFileToS3(file, 'user'); const target = { profileImage: imageFile.Location }; await User.update(target, { where: { id: userId, }, }); return imageFile; } catch (err) { throw new Error(errorName.PROFILE_IMAGE_UPDATE_ERROR); } }
const insertPost = async (file, postInfo) => { try { const imageFile = await uploadImageFileToS3(file, 'post'); const result = await Post.create({ imageURL: imageFile.Location, postURL: short.generate(), content: postInfo.content, updatedAt: new Date(), UserId: postInfo.userId, }); const postId = result.dataValues.id; hashtagService.insertHashTagOfPost(postInfo.content, postId); usertagService.insertUserTag(postInfo.content, postId); return result.dataValues; } catch (err) { if (isErrorOfTagInsertion) throw err; throw new Error(errorName.POST_INSERT_ERROR); } }