Skip to content

Instantly share code, notes, and snippets.

@bunnyhawk
Created October 30, 2020 18:13
Show Gist options
  • Save bunnyhawk/eca4605af72f7145be5cfa483cf1663d to your computer and use it in GitHub Desktop.
Save bunnyhawk/eca4605af72f7145be5cfa483cf1663d to your computer and use it in GitHub Desktop.
aws nodemailer example submit
const API_URL = 'https://XXXXXXXXX.execute-api.us-west-2.amazonaws.com/dev/send-mail';
const onSubmit = async (event) => {
event.preventDefault();
submitButton.disabled = true;
const { submissionProof, ...rest } = Object.fromEntries(new FormData(event.target).entries());
const body = new FormData();
Object.keys(rest).forEach((name) => {
body.append(name, rest[name]);
});
[...fileSubmit.files].forEach((file) => {
body.append(file.name, file);
});
try {
const response = await fetch(API_URL, {
method: 'POST',
body,
});
} catch (err) {
submitButton.disabled = false;
}
submitButton.disabled = false;
window.location.href = '/submitted/';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment