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

phpMick's avatar
Level 15

Vue parse and then upload an xml file.

I'm struggling with this.

I want to parse a xml file (Jasper Report Template), so that I can store some parameters which are in it.

I was looking at this : https://codepen.io/Atinux/pen/qOvawK

Do I need to do reader.readAsDataURL(file); surely this should be simple?

I also want to upload the file with Axios.

HTML

<input type="file" name="fileToUpload" id="fileToUpload" @change="fileUploaded" v-model="fileToUpload">
fileUploaded: function (event) {

        self = this;
            
        var file = e.target.files[0];
        var file = document.getElementById("fileToUpload").files[0];
        //You could insert a check here to ensure proper file type


        var reader = new FileReader();
        reader.readAsText(file);
        reader.onloadend = function(){

            var parser = new DOMParser();
            var doc = parser.parseFromString( reader.result, "application/xml");
            var params = doc.querySelectorAll('parameter');

             for (var i = 0; i < params.length; i++) {
                self.jasperParams.push(params[i].getAttribute('name'));
             }

        }

        },

axios.post('/' + self.table,{

                name: self.name,
                sql:self.SQL,
                area_id:self.area_id,
                report_type_id:self.report_type_id,
                fileToUpload:self.fileToUpload
0 likes
3 replies
phpMick's avatar
Level 15

I have added this now:

 let files = event.target.files || event.dataTransfer.files;
        self.fileToUpload = files[0];

I have added it to the post:

 axios.post('/' + self.table,{

                name: self.name,
                sql:self.SQL,
                area_id:self.area_id,
                report_type_id:self.report_type_id,
                fileToUpload:self.fileToUpload

            })

Looking in the developer tools, it looks like the file is loaded but It's empty in the request:

fileToUpload:{}

Grrrr

Also just tried this:

 let data = new FormData();
 data.append('file', self.fileToUpload);
  fileToUpload:data

monsieurmechant's avatar

I would probably let the back-end handle it and return the values that you want.

phpMick's avatar
Level 15

So, how would you do the upload then?

I have the parsing but working, but not the upload.

Please or to participate in this conversation.