Upload multiple files using the same request?

2

I'm using the VueJS / Quasar Framework to make the front end of my application and HapiJS to do the server. And in the part of uploading the attachments I'm testing with multiple upload files, and I came across the following problem:

For each file QUploader makes a request to the server ( QUploader is the Quasar component I'm using to select the files and upload the upload).

Follow the code below:

Front-end VueJS / Quasar Framework

<q-uploader multiple :url="url.url" color="light-blue-10" />

Component that I use to upload

HapiJS Server:

server.route({
path: '/upload',
method: 'post',
config: {
    payload: {
        output: 'stream',
        parse: true,
        allow: 'multipart/form-data'
    },
    cors: {
        origin: ['*'],
        additionalHeaders: ['cache-control', 'x-requested-with', 'Accept',
            'Authorization', 'Content-Type', 'f-None-Match', 'Accept-language']
    }
},
handler: function (request, reply) {
    let data = request.payload;
    if (data.file) {
        let name = data.file.hapi.filename;
        let path = __dirname + "/uploads/" + name;
        let file = fs.createWriteStream(path);
        file.on('error', function (err) {
            console.error(err)
        });

        data.file.pipe(file);

        data.file.on('end', function (err) {
            let ret = {
                filename: data.file.hapi.filename,
                headers: data.file.hapi.headers
            };
            return reply.response(JSON.stringify(ret));
        })
    }
}
});

How do I do all downloads on the same request ??

    
asked by anonymous 04.09.2017 / 22:12

0 answers