Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Pixelairport's avatar

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);
            })
        }
0 likes
1 reply
Pixelairport's avatar
Pixelairport
OP
Best Answer
Level 12

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 or to participate in this conversation.