Send file with custom nova field Hi. I try to create a custom field to upload files to spatie medialibrary, but the file is not sent to API. Does anybody have an idea? This is my code:
uploadDownload(event) {
let uploadFile = this.$refs['attachment'].files[0];
console.log(uploadFile); // This works.
Nova.request().post('/myvendor/medialibrary/endpoint', {
upload: uploadFile
}, {
headers: {
'Content-Type': 'multipart/form-data'
}
} ).then(response => {
console.log(response);
})
}
Ok now it works. :)
let formData = new FormData();
formData.append('upload', this.$refs['attachment'].files[0]);
const config = {
headers: {
'accept': 'application/json',
'Accept-Language': 'en-US,en;q=0.8',
'Content-Type': `multipart/form-data`
}
};
Nova.request().post('/myproject/medialibrary/', formData, config).then(response => {
console.log(response)
}).catch(error => {
console.log(error)
})
Please sign in or create an account to participate in this conversation.