I’m wondering how to send Javascript File object to AWS Lambda. I have a File object which collected from <input type="file">
and formed as File()
object. I’m sending the File()
object through an HTTP request to AWS Lambda but ended up getting undefined on the Lambda function.
Front End(Javascript)
let uploadFile = new File(
[file],
Date.now() + " - " + file.name,
{type: file.type}
)
const body = {
payload: {
file: uploadFile,
comment: "Uploading File."
}
}
fetch(url, {
method: "POST",
headers: {
"Authorization": token,
"Content-Type": "application/json"
},
body: body
}).catch((err) => {
reject(err.json());
});
Back End (AWS Lambda, Typescript)
const handler = async (event: APIGatewayProxyEventV2): Promise<any> => {
console.log("Whole Event Body:", event.body);
console.log("Event Body Payload:", event.body.payload);
...
}
I’m just getting undefined
from the event
. I wonder am I doing it correctly? Is it possible to pass the File()
object to AWS Lambda?