Level 4
Error
Access to XMLHttpRequest at 'url/api/document_update' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I keep getting this cors error whenever I try to upload a file from my vue js frond end to my laravel API backend
//vue form
<form method="post" enctype="multipart/form-data">
<input type="file" accept="application/pdf" ref="identity" id="identity" v-on:change="handleFileUpload(), submitFile()" style="display: none">
<b-button @click="$refs.identity.click()" class="outline small">Open Finder</b-button>
</form>
// script
methods: {
/*
Submits the file to the server
*/
submitFile(){
/*
Initialize the form data
*/
let formData = new FormData();
/*
Add the form data we need to submit
*/
formData.append('identity', this.identity);
Vue.axios.put('url/api/document_update', formData,
{
headers: {
'Content-Type': 'multipart/form-data'
}
})
}
}
Please or to participate in this conversation.