Upload multiple files using the same request?

Asked

Viewed 210 times

2

I am using the Vuejs/Quasar Framework to do the front end of my application and Hapijs to do the server. And in the uploading part of the attachments I’m running a test with uploading multiple 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 re-upload).

Follows code:

Front-end Vuejs/Quasar Framework

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

Component I use to upload

Servidor Hapijs:

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 make all downloads on the same request??

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.