Im using a lambda to handle images upload.
When i upload 2 images it is working fine. But once i upload more than 4 images, api return 413 request too long.
i noted that there is a limit of Invocation payload. Is there any ways to handle this upload action? or any suggestion?
Please help, thanks and regards!
module.exports = {
create: async (info, files) => {
if (!info.shop_id || !info.username || !info.comment) {
response = getResponse(400, {
code: "FAIL",
message: "FAIL",
});
return response;
}
const member = await knex("members").where("username", "=", info.username);
const Comment_id = await knex(tableName).returning("id").insert({
shop_id: info.shop_id,
user_id: member[0].id,
comment: info.comment,
attachment: info.attachment,
});
if (info.attachment) {
//upload files to s3
for (let index = 0; index < files.length; index++) {
const element = files[index];
let d = new Date();
const file_name = `c${Comment_id}-${index}-${d.getDate()}-${d.getMonth()}-${d.getFullYear()}.${
element.mimetype.split("/")[1]
}`;
const destparams = {
Bucket: s3_config.Bucket,
Key: `shop/comments/${"s" + info.shop_id}/${file_name}`,
Body: element.buffer,
ContentType: "image",
ACL: "public-read",
};
try {
const putResult = await s3.putObject(destparams).promise();
} catch (error) {
console.log(error);
}
const addFile = await knex("files").insert({
mapping_id: Comment_id[0],
type: "COMMENT_FILE",
path: `${s3_config.host}shop/comments/${
"s" + info.shop_id
}/${file_name}`,
});
}
}
response = getResponse(200, {
code: "SUCCESSFUL",
message: "SUCCESSFUL",
comment_id: Comment_id,
});
return response;
},
update: async (id, info) => {
const isExist = await knex(tableName).where("id", "=", id);
if (!isExist || !info) {
response = getResponse(400, {
code: "FAIL",
message: "FAIL",
});
return response;
}
const result = await knex(tableName).where("id", "=", id).update({
comment: info,
});
if (!result) {
response = getResponse(400, {
code: "FAIL",
message: "FAIL",
});
} else {
response = getResponse(200, {
code: "SUCCESSFUL",
message: "SUCCESSFUL",
});
}
return response;
},
delete: async (id) => {
const isExist = await knex(tableName).where("id", "=", id);
if (!isExist) {
response = getResponse(400, {
code: "FAIL",
message: "FAIL",
});
return response;
}
const result = await knex(tableName).where("id", id).del();
if (result) {
response = getResponse(200, {
code: "SUCCESSFUL",
message: "SUCCESSFUL",
});
} else {
response = getResponse(400, {
code: "FAIL",
message: "FAIL",
});
}
return response;
},
}
question from:
https://stackoverflow.com/questions/66049186/aws-s3-lambda-upload-return-413-request-too-long