Skip to content

Commit

Permalink
fix: aws explicitly throw error, change to new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
hwmin414 committed Mar 12, 2024
1 parent b99418c commit f83acaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 30 deletions.
28 changes: 12 additions & 16 deletions src/modules/stores/aws.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,18 @@ module.exports.getUploadPUrlPut = async (

// function to generate signed-url for upload(POST)
module.exports.getUploadPUrlPost = async (filePath, contentType) => {
try {
const presignedUrl = await getSignedUrl(
s3,
new PutObjectCommand({
Bucket: awsEnv.s3BucketName,
Key: filePath,
contentType: contentType,
}),
{
expiresIn: 60,
}
);
return presignedUrl;
} catch (e) {
return e;
}
const presignedUrl = await getSignedUrl(
s3,
new PutObjectCommand({
Bucket: awsEnv.s3BucketName,
Key: filePath,
contentType: contentType,
}),
{
expiresIn: 60,
}
);
return presignedUrl;
};

// function to delete object
Expand Down
16 changes: 2 additions & 14 deletions src/services/chats.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,20 +243,8 @@ const uploadChatImgGetPUrlHandler = async (req, res) => {
});
const chat = await chatDocument.save();
const key = `chat-img/${chat._id}`;
aws.getUploadPUrlPost(key, type, (err, data) => {
if (err) {
return res
.status(500)
.send("Chat/uploadChatImg/getPUrl : internal server error");
}
data.fields["Content-Type"] = type;
data.fields["key"] = key;
res.json({
id: chat._id,
url: data.url,
fields: data.fields,
});
});
const data = await aws.getUploadPUrlPost(key, type);
res.json({ url: data, id: chat._id });
} catch (e) {
logger.error(e);
res.status(500).send("Chat/uploadChatImg/getPUrl : internal server error");
Expand Down

0 comments on commit f83acaa

Please sign in to comment.