my task is to make a form to send an Excel file and a message to the server, and I have a postman collection file that contains this array of objects:
"formdata": [
{
"key": "message",
"value": "hello",
"type": "text"
},
{
"key": "users",
"type": "file",
"src": "path-to-.xlsx"
}
]
and this is my simple form:
<div class="landing">
<div class="intro-text">
<div class="form-style-3">
<form id="msgform" method="POST">
<fieldset>
<legend>Message</legend>
<label for="file">
<span>File
<span class="required">*</span>
</span>
<input type="file" name="file" id="input"
accept="..csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel" />
</label>
<label for="message">
<span>Message
<span class="required">*</span>
</span>
<input name="message" id="message" type="text" />
</label>
<label>
<input type="submit" value="Submit" />
</label>
</fieldset>
</form>
</div>
</div>
</div>
and this is my API connection function:
const url = 'path-to-api-url';
const form = document.getElementById('msgform');
form.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(form);
const formDataSerealized = Object.fromEntries(formData);
console.log(formDataSerealized);
try {
const response = await fetch(url, {
method: 'POST',
body: JSON.stringify(formDataSerealized),
headers: {
'Content-type': 'application/json',
},
});
const json = await response.text();
console.log(json);
} catch (e) {
console.error(e);
}
});
My problem is when submitting I have in the console this error
{"errors":[{"message":"message not found"}]}
What Should I do?