/hapi-jfu

jQuery-File-Upload Hapi.js Middleware | Go for new version :

Primary LanguageJavaScriptMIT LicenseMIT

hapi-jfu

jQuery-File-Upload Hapi.js Middleware

Dependency Status devDependency Status Build Status

jQuery-File-Upload Hapi.js Middleware. Based on the server code of jQuery-File-Upload

Installation:

    $ npm install hapi-jfu --save

Usage:

    server.route({
        method: 'POST',
        path: '/',
        config: {
            tags: ['api'],
            payload: {
                maxBytes: 209715200,
                output: 'stream',
                parse: false
            }
        },
        handler: function (request, reply) {

            const upload = request.server.plugins['storage/image'].jfu;

            upload.configure({
                uploadDir: './public/storage',
                uploadUrl: './storage',
                imageVersions: {
                    thumbnail: {
                        width: 80,
                        height: 80
                    }
                },
                server: {
                    request: request,
                    reply: reply
                }
            });

            upload.fileHandler();
        }
    });

Important : always need to configure payload in route with two parameter output and parse addition you should always pass request and reply parameter like above in configuration too .

On the frontend:

   <input id="fileupload" type="file" name="files[]" data-url="/upload" multiple>
   <script>$('#fileupload').fileupload({ dataType: 'json' })</script>

Other options and their default values:

{
    tmpDir: '/tmp',
    uploadDir: __dirname + '/public/uploads',
    uploadUrl: '/uploads',
    targetDir: uploadDir,
    targetUrl: uploadUrl,
    ssl: false,
    hostname: null, // in case your reverse proxy doesn't set Host header
                    // eg 'google.com'
    maxPostSize: 11000000000, // 11 GB
    minFileSize: 1,
    maxFileSize: 10000000000, // 10 GB
    acceptFileTypes: /.+/i,
    imageTypes: /\.(gif|jpe?g|png)$/i,
    imageVersions: {
        thumbnail: {
            width: 80,
            height: 80
        }
    },
    imageArgs: ['-auto-orient'],
    accessControl: {
        allowOrigin: '*',
        allowMethods: 'OPTIONS, HEAD, GET, POST, PUT, DELETE'
    }
}

Forked from

jquery-file-upload-middleware

License

Copyright (c) 2017 Amir Irani
Released under the MIT license.