olebulow's avatar

Upload files with vue in spark

Hi all,

So im trying to post a form via ajax with Vue+Spark. The form consists of two text inputs and a file input. The serverside part is working (tested in postman) and the form works as well in regards to the text inputs, but the image is not being sent.

HTML:

<form id="sponsorAdd" role="form" enctype="multipart/form-data">
<input type="file" accept="image/*" name="logo" id="logo" class="form-control">
<input type="text" class="form-control" v-model="addSponsorForm.name" placeholder="Name">
<input type="text" class="form-control" v-model="addSponsorForm.byline" placeholder="Byline">
</form>

Vue:

addSponsor() {
            Spark.post('/api/sponsor/' + this.id, this.addSponsorForm)
                .then(response => {
                    $('#modal-AddSponsorForm').modal('hide');
                    this.addSponsorForm.name = '';
                    this.addSponsorForm.byline = '';
                    this.addSponsorForm.logo = '';
                });
        },

Now, I've read pages up and down about the limitations in vie-resource and uploading, and found lots of working examples when it comes to just uploading 1 or more images. But i simply can't figure out how to get the rest of the form inputs with the image.

Any ideas?

0 likes
0 replies

Please or to participate in this conversation.