Не получается отправить файл post запросом в fetch
Возникла проблема с отправкой файла через post запрос. Я отправляю сообщение,но у меня выходит ошибка 403.Буду рад любой помощи!
document.querySelector('.upload_files').addEventListener('click', function(event) {
event.stopPropagation();
event.preventDefault();
const fileInput = document.getElementById("file").files[0];
console.log(fileInput);
const cont = {
"project_id": 14497,
"file": document.getElementById("file").files[0]
}
let url = 'https://brizo.ru/api/v1/field-file';
fetch(url, {
method: 'POST',
headers: {
'Content-type': 'multipart/form-data',
'Authorization': 'Bearer qOzco4BasgCsktWyYBkHfHCftcC0iLEWfwiawx2XpiRsGt8d8c12MrRj43sI',
headers: {
'X-Brad-Test': 'true'
},
cache: 'no-store',
mode: 'no-cors'
},
body: JSON.stringify(cont)
})
.then(response => console.log(response));
})
<form enctype="multipart/form-data" method="post" action="#">
<p>
<input type="file" id="file" name="file" />
</p>
<p>
<input class="upload_files" type="submit" value="Отправить" />
</p>
</form>
Источник: Stack Overflow на русском