Code Monkey home page Code Monkey logo

jquery-file-upload-middleware's Introduction

jquery-file-upload-middleware

jQuery-File-Upload Express.js middleware. Based on the server code of jQuery-File-Upload

Installation:

    $ npm install jquery-file-upload-middleware

Usage:

    var express = require("express"),
        upload = require('jquery-file-upload-middleware');

    var app = express();

    // configure upload middleware
    upload.configure({
        uploadDir: __dirname + '/public/uploads',
        uploadUrl: '/uploads',
        imageVersions: {
            thumbnail: {
                width: 80,
                height: 80
            }
        }
    });

    app.configure(function () {
        ...
        app.use('/upload', upload.fileHandler());
        app.use(express.bodyParser());
        ...
    });

On the frontend:

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

To prevent access to /upload except for post (for security)

upload.configure({
    uploadDir: __dirname + '/public/uploads/',
    uploadUrl: '/uploads'
});

/// Redirect all to home except post
app.get('/upload', function( req, res ){
	res.redirect('/');
});

app.put('/upload', function( req, res ){
	res.redirect('/');
});

app.delete('/upload', function( req, res ){
	res.redirect('/');
});

app.use('/upload', function(req, res, next){
    upload.fileHandler({
        uploadDir: function () {
            return __dirname + '/public/uploads/'
        },
        uploadUrl: function () {
            return '/uploads'
        }
    })(req, res, next);
});

Overriding global configuration

    app.use('/upload2', upload.fileHandler({
        uploadDir: __dirname + '/public/uploads2',
        uploadUrl: '/uploads2',
        imageVersions: {
            thumbnail: {
                width: 100,
                height: 100
            }
        }
    }));

More sophisticated example - Events

        app.use('/upload', upload.fileHandler());

        // events
        upload.on('begin', function (fileInfo, req, res) { 
            // fileInfo structure is the same as returned to browser
            // { 
            //     name: '3 (3).jpg',
            //     originalName: '3.jpg',
            //     size: 79262,
            //     type: 'image/jpeg',
            //     delete_type: 'DELETE',
            //     delete_url: 'http://yourhost/upload/3%20(3).jpg',
            //     url: 'http://yourhost/uploads/3%20(3).jpg',
            //     thumbnail_url: 'http://youhost/uploads/thumbnail/3%20(3).jpg' 
            // }
        });
        upload.on('abort', function (fileInfo, req, res) { ... });
        upload.on('end', function (fileInfo, req, res) { ... });
        upload.on('delete', function (fileInfo, req, res) { ... });
        upload.on('error', function (e, req, res) {
            console.log(e.message);
        });

Dynamic upload directory and url, isolating user files:

        upload.configure({
            imageVersions: {
                thumbnail: {
                    width: 80,
                    height: 80
                }
            }
        });

        app.use('/upload', function (req, res, next) {
            // imageVersions are taken from upload.configure()
            upload.fileHandler({
                uploadDir: function () {
                    return __dirname + '/public/uploads/' + req.sessionID
                },
                uploadUrl: function () {
                    return '/uploads/' + req.sessionID
                }
            })(req, res, next);
        });

Moving uploaded files to different dir:

        app.use('/api', function (req, res, next) {
            req.filemanager = upload.fileManager();
            next();
        });

        app.use('/api/endpoint', function (req, res, next) {
            // your real /api handler that will actually move the file
            ...
            // req.filemanager.move(filename, path, function (err, result))
            req.filemanager.move('SomeFile.jpg', 'project1', function (err, result) {
                // SomeFile.jpg gets moved from uploadDir/SomeFile.jpg to
                // uploadDir/project1/SomeFile.jpg
                // if path is relative (no leading slash), uploadUrl will
                // be used to generate relevant urls,
                // for absolute paths urls are not generated
                if (!err) {
                    // result structure
                    // {
                    //     filename: 'SomeFile.jpg',
                    //     url: '/uploads/project1/SomeFile.jpg',
                    //     thumbail_url : '/uploads/project1/thumbnail/SomeFile.jpg'
                    // }
                    ...
                } else {
                    console.log(err);
                }
            });
        });

Moving uploaded files out of uploadDir:

        app.use('/api', function (req, res, next) {
            var user = db.find(...);

            req.filemanager = upload.fileManager({
                targetDir: __dirname + '/public/u/' + user._id,
                targetUrl: '/u/' + user._id,
            });

            // or
            req.filemanager = upload.fileManager({
                targetDir: function () {
                    return __dirname + '/public/u/' + user._id
                },
                targetUrl: function () {
                    return'/u/' + user._id
                }
            });
            ...
            req.filemanager.move(req.body.filename, 'profile', function (err, result) {
                // file gets moved to __dirname + '/public/u/' + user._id + '/profile'
                if (!err) {

                }
            });
        });

Getting uploaded files mapped to their fs locations:

        app.use('/list', function (req, res, next) {
            upload.fileManager().getFiles(function (files) {
                //  {
                //      "00001.MTS": {
                //          "path": "/home/.../public/uploads/ekE6k4j9PyrGtcg+SA6a5za3/00001.MTS"
                //      },
                //      "DSC00030.JPG": {
                //          "path": "/home/.../public/uploads/ekE6k4j9PyrGtcg+SA6a5za3/DSC00030.JPG",
                //          "thumbnail": "/home/.../public/uploads/ekE6k4j9PyrGtcg+SA6a5za3/thumbnail/DSC00030.JPG"
                //      }
                //  }
                res.json(files);
            });
        });

        // with dynamic upload directories

        app.use('/list', function (req, res, next) {
            upload.fileManager({
                uploadDir: function () {
                    return __dirname + '/public/uploads/' + req.sessionID
                },
                uploadUrl: function () {
                    return '/uploads/' + req.sessionID
                }
            }).getFiles(function (files) {
                res.json(files);
            });
        });

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'
    }
}

Contributors

License

Copyright (c) 2012 Aleksandr Guidrevitch Released under the MIT license.

jquery-file-upload-middleware's People

Contributors

aguidrevitch avatar andineck avatar derjust avatar dudemullet avatar mberlanda avatar olalonde avatar peecky avatar soomtong avatar tonyspiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jquery-file-upload-middleware's Issues

do not download with imageVersions

error in cmd:
"
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:945:11)
at Process.ChildProcess._handle.onexit (child_process.js:736:34)
"
without imageVersions - ok

thank you

Cannot create thumbnails

This middle ware is working fine but when trying to upload image files the thumbnails are not created and the server is halted. When ever I try to upload image files I get the below message logged in my terminal :

events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)
10 Nov 12:30:41 - [nodemon] app crashed - waiting for file changes before starting...

I have installed 'swig' and 'imagemagick' dependencies also.

Problem with server-side progress

Hi, your project looks great, but I have a problem I can't resolve :

I use the original jQuery file Upload form (the demo form) and I just modify the url in main.js to :

        url: 'http://localhost:3000/upload/stockEntryImage'

instead of :

        url: 'http://localhost:8888/'

when I want to use the server.js from the original project.

The fact is that the progress never ends in the front-end when I use your code.

I added this console.log to see the progress of the upload.

         .on('progress', function (bytesReceived, bytesExpected) {

            console.log("progress : "+bytesReceived+"/"+bytesExpected);

            if (bytesReceived > options.maxPostSize) {
                handler.req.connection.destroy();
           }

And it shows me this :
progress : 0/418959

and that's all, but when I use the original server.js I have this :
progress : 73789/418957
progress : 139325/418957
progress : 204861/418957
progress : 270397/418957
progress : 335933/418957
progress : 401469/418957
progress : 418957/418957

And it goes to the onFile event, thing that never happens with your code.

BUT, and here is what I don't understand, in each case I have the file successfully written to the /tmp/ directory.

Do you know from where comes the problem ?

Question on modifying json result

Hi, I'm trying to figure out how to insert an additional value into the JSON response that gets sent back to the client. I'm pretty new to both Express and Node so forgive me if the answer is obvious. I'm using the upload.on('end') event to store some information about the uploaded file in a database and I want to take an id I get back from the database and send it back to the client in the JSON response. I tried something like fileInfo.myKeyName = 'some_new_key' at the end of upload.on('end'), but that does not appear to modify fileInfo prior to sending back the result. What would be the best way to modify that JSON response? Thanks for any help you can provide and thanks for making this module. It's really helpful.

File is too small

Hi.
I'm using your plugin and it works great but it doesn't seem to accept a image less them 100kb even if I use the option minFileSize: 1

How can I solve this? I work with upload of small thumbs and generally the images have less than 100kb.

This is my code ( also try to put the options on the upload.configure but it didn't help:

upload.fileHandler({
    uploadDir : function() {
        return config.app.uploadFolder + "/" + req.query.folder
    },
    uploadUrl : function() {
        return  "/a/img/" + req.query.folder 
    },
    maxPostSize: 1100000000, // 1 GB
    minFileSize: 1,
    maxFileSize: 1000000000 // 1 GB
})(req, res, next);

switch to gm

Any plan to switch from imagemagick to gm?. Seems like imagemagick is not actively maintained.

IE9 always shows a download popup for files.json

On IE9 with fallback to IFrame transport, the browser always popups a download save as window for "files.json".

Is there a specfic reason for sending the Content-Disposal header?
I dropped it as per derjust@56c640a and everything looks good now.

Also at the jQuery file upload docu I couldn't find a reference to this header. (Only the obvious one about content type blueimp/jQuery-File-Upload#1795)
I checked the content type and it set to plain/text as per jQuery documentation.

Maybe due to a missing, additional nosniff this could be solved in a cleaner way?

Recently working code patched

please checkout https://github.com/soomtong/jquery-file-upload-middleware

  • use bower to install jquery-file-upload
  • use not npm to install jquery-file-upload-middleware
  • use this repository by
{
    "name": "your project",
    "version": "0.1.0",
    "private": true,
    "dependencies": {
        "express": "3.3.x",
        "jquery-file-upload-middleware": "git://github.com/soomtong/jquery-file-upload-middleware.git",
        "swig": "1.0.x",
        "imagemagick": "0.1.x"
    },
    "devDependencies": {
        "nodeunit":"*"
    }
}

working example included.

cap 2013-09-06 17-18-05-275

cap 2013-09-06 17-18-38-805

How/where do I grab extra 'formData' sent by the client

Hi, I am using the middleware to handle uploads in a pretty basic manner. However, I send extra info along with the file in order do additional processing for it on the server. I don't see it echoed back in the response, and I added an .on('begin',..) handler to inspect the 'fileInfo' passed and it doesn't include it as well. Is the extra formData ignored by this middleware?

Imagemagick doesnt worcks

Hi,

I installed image magic on my win7 and it works.(I can use convert comand line)

But in my thumbnail folder, i still dont have any images uploaded.

Otherwise the midleware works perfectly. Thank you for your work.

My question : Is there any configuration to make image resize work? For now i just added this ine the option.
imageVersions: {
thumbnail: {
width: 80,
height: 80
}
}

Uploading successful not returning anything to client on POST.

I've gotten the middleware to properly upload the files, but the done event's isn't getting triggered because it seems like the middleware isn't returning anything on the post. What am I doing wrong? I've attached a screen of the xhr request which successfully uploads, but doesn't get anything back...

upload.configure({
    uploadDir: __dirname + '/uploads',
    uploadUrl: '/upstream',
    imageVersions: {
        thumbnail: {
            width: 80,
            height: 80
        }
    }
});

...


app.use('/upstream', upload.fileHandler());

screen shot 2013-06-10 at 2 40 12 am

maxChunkSize splitting file into multiple files

If I use the maxChunkSize option, the uploaded file get split into multiple files - how can I get them to join automatically?

I could just turn off maxChunkSize but I'm uploading big files (a few GB).

[Error: Request aborted] on localhost

When I upload images then I getting this error. [Error: Request aborted].

In filehandler.js this function is execute

handler.on('error', function (e) {
console.log(e);
middleware.emit('abort', e, req, res);
});.

So I am unable to get this images in router.
Is there any change required to make in configuration?.

Forget to add lib to npm

the lib dir is not included in the version available on npm.
The version on the npm registry is 0.0.3 while the latest version in the repo is 0.0.4.

I guess you just need to npm publish :)

Cheers!

Image conversion doesn't work

Hi,
awesome work, uploading works fine.
But if I upload an image and have imageVersions set:

upload.configure({
uploadDir: __dirname + '/public/uploads',
uploadUrl: '/uploads',
imageVersions: {
thumbnail: {
width: 80,
height: 80
}
}
});

I get the following error:
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:975:11)
at Process.ChildProcess._handle.onexit (child_process.js:766:34)

Any idea what this is due?

ps.

  • I've tried running node through sudo, no change
  • Uploading works perfectly fine

how to handle events depend on different router ?

At the first, thanks to the plugin, it helps me a lot.

now I use the middleware on different router, it's like:

router.post(path1, upload.fileHandler(option1));
router.post(path2, upload,fileHandler(option2));

and base on different router, I want to handler end event in different ways.
Actually, I can set req.type or something like that, but which I don't think is the best solution.
So, how can I do?

Thanks.

Dynamic Dir does not work

I'm trying to use dynamic dir but not working when i put my upload configuration after

app.use(passport.initialize());
app.use(passport.session());

I need to put after this because i want to use the req.user._id and this info come from my passport and it's only available before passport.initialize() and passport.session()

When i put my upload config before app.use(passport.initialize());, without dynamic dir, all runs as expected.

Saving new file data on server

My code:

var path = req.params.path;
upload.fileHandler({
tmpDir: config.get('app_path') + '/tmp',
uploadDir: config.get('app_path') + '/public/uploads/'+path,
uploadUrl: '/uploads/'+path
})(req,res);

    upload.on('end', function (fileInfo) {

        File.findOne({'url':fileInfo.url},function(err,finded){

            if(!finded) {
                var file = new File({
                    url:fileInfo.url,
                    name:fileInfo.name,
                    originalName:fileInfo.originalName,
                    size:fileInfo.size,
                    type:fileInfo.type,
                    directory:path
                });

                file.save(function (err, saved) {
                    if (err) log.error(err);
                })
            }
        });

    });

When you first load the file entirely perfect! When the function(upload.on('end',function) is performed subsequent to 1 times. As a result, my file is stored several times in the database. How to solve this problem?

Failed to load resource: net::ERR_CONNECTION_REFUSED

I am getting the following error when using the "imageVersions" option. If i remove it the upload works fine. Any idea what's causing it and how to fix? Thank you.

node: v0.11.12
express: 4.0.0

.write(string, encoding, offset, length) is deprecated. Use write(string[, offset[, length]][, encoding]) instead.
events.js:82
      throw er; // Unhandled 'error' event
            ^
Error: spawn ENOENT
    at exports._errnoException (util.js:745:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1027:32)
    at child_process.js:1108:20
    at process._tickCallback (node.js:339:11)

Submit form on upload

There are times, when you want your user to upload only one file, in which case the extra "submit" button is redundant. Made attempts to submit form on upload in file_upload,js with
$("#gallery_dropzone").on("success", function () {
$('#location_upload').submit();
});
(can't do it in form as "update" button is dynamically created after form is read). Ideas?

Thanks - Every else working great.

Rename files

Is it possible to rename files before responding to the client?
Thus, when I do something like:

upload.on "end", (fileinfo) ->
  console.log fileinfo

fileinfo's name is a rename one and NOT the original file's names!

Thank you!

Running middleware before uploading

Before I let a user upload files, I want to perform an authentication check.

The uploading works fine if I just use the middleware like this:

app.use('/upload/blogs', function (req, res, next) {
    upload.fileHandler({
        uploadDir: function () {
            return __dirname + '\\public\\uploads\\blogs\\';
        },
        uploadUrl: function () {
            return '/uploads/blogs';
        }
    })(req, res, next);
});

If I add any sort of async middlerware prior to above code, the upload does nothing. e.g. adding the following use before the above code:

app.use(function (req, res, next) {
    var token = req.headers["x-authenticationtoken"];
    if (token == null)
        return next();
    tokenRepository.getUserByToken(token, function (result) {
            if (result.error != null) {
                req.currentUser = null;
                console.log("Not logged in");
            }
            else {
                req.currentUser = result.data;
                console.log("user authenitcated");
            }
            next();
        }
    );
});

If I comment out the async part like this, it will work:

app.use(function (req, res, next) {
//    var token = req.headers["x-authenticationtoken"];
//    if (token == null)
//        return next();
//    tokenRepository.getUserByToken(token, function (result) {
//            if (result.error != null) {
//                req.currentUser = null;
//                console.log("Not logged in");
//            }
//            else {
//                req.currentUser = result.data;
//                console.log("user authenitcated");
//            }
//            next();
//        }
//    );
    next();
});

Any ideas on what I'm doing wrong?

Trigger File Rename, S3 upload

I would like to rename the file that was uploaded to another name, and upload it to S3.

Where do you suggest I do this work? Should this be done on the FileHandler piece, or when the object gets returned to the page?

Uploads not working

I am trying to implement this module with the demo front-end supplied by blue-imp. The server.js in the demo works fine but the module doesn't. I don't get any errors but when the upload starts on the browser I can see the post but it just stays in the pending state and no file is uploaded. The client eventually timesout. Do you have any ideas why this might be or how I can debug it?

Orientation

Thank you for this very useful library. I only have 1 question, is it possible to grab to orientation value from the file and save the file (in case it concerns an image) in the correct orientation? Or, if this is not possible, provide the orientation value in the response?

Very Nice

Very nice initiative. I will use it in my projects and give you feedback if any :)

Thank you for creating the middleware mate ^^

Question: How to get user's upload directory name in the upload event handler?

Hi! Could you look through the issue below please?

app.use('/upload', function (req, res, next) {
            // imageVersions are taken from upload.configure()
            upload.fileHandler({
                uploadDir: function () {
                    return __dirname + '/public/uploads/' + req.sessionID
                },
                uploadUrl: function () {
                    return '/uploads/' + req.sessionID
                }
            })(req, res, next);
        });
upload.on('end', function (fileInfo) {
   // I want to get __dirname + '/public/uploads/' + req.sessionID here without regexp- parsing fileInfo.url variable
});

Enhancement : UploadHandler.prototype.initUrls BaseUrl behind reverse-proxy

Hi,

Very nice job you have done with this code. I'm wondering if you could improve initUrls function to handle case when your are behind a reverse-proxy.

var baseUrl = (options.ssl ? 'https:' : 'http:') + '//' + this.req.headers.host;

In my case, this.req.headers.host is rendering IP and Port instead of the url type in the browser.

Is it possible to cach it ?

Thanks,
Olivier

Create Additional Event?

I want to be able to trigger an additional event after the files have been uploaded. For example, after I upload an XML file, I would like to be able to hit a "Load Data" button which will take the file and do some stuff with it on the server side.

I have the GUI setup properly, and I added a few entries to filehandler.js and uploadhandler.js

image

//FILEHANDLER.js
handler.on('loadAction', function (fileName) {
        middleware.emit('load', fileName);
    });

//UPLOAD HANDLER.JS
.on('loadAction', function (e) {
            self.emit('load', e);
        })

I'm looking to do something like the below via the Middleware:

upload.on('loadAction', function (fileName) {
        console.log("Loading File: " + fileName);
        //some custom business logic here
    });

I'm not sure how to go about making this tweak... but it WOULD be a nice feature for the middleware down the road :)

The return JSON data is not compatible with jQuery File Upload Plugin's requirement

Hi,
I am using jQuery File Upload Plugin's client code and jquery-file-upload-middleware as backend server.
I found a problem is that the jquery-file-upload-middleware return JSON data is not compatible with jQuery File Upload Plugin's requirement, then the problem "Empty file upload result" is always represent. However, the file is upload succeed, just the client can not properly display the result.

I catch the request and found the return JSON data is:
[
{
"name": "iPhone5 docking station.jpeg",
"originalName": "iPhone5 docking station.jpeg",
"size": 9584,
"type": "image/jpeg",
"delete_type": "DELETE",
"url": "http://localhost/uploads/iPhone5%20docking%20station.jpeg",
"delete_url": "http://localhost/product/upload/iPhone5%20docking%20station.jpeg",
"thumbnail_url": "http://localhost/uploads/thumbnail/iPhone5%20docking%20station.jpeg"
}
]

And i google this issue found a issue on jQuery File Upload Plugin's page: blueimp/jQuery-File-Upload#365
There @OneDivZero said the latest jQuery File Upload Plugin's JSON format was changed from: [{file1}, {file2}] to: {files: [{file1}, {file2}]}.

So i try to change the jquery-file-upload-middleware code in lib/filehandler.js:
//res.json(200, result);
//MODIFY & TODO, should sumbit issue to the https://github.com/aguidrevitch/jquery-file-upload-middleware
res.json(200, {files: result});

Then everything is fine.

Is this a bug?

Bug in documentation of Dynamic upload dir

Shoulnd't you add a next() at the end of the configuration?

        app.use('/upload', function (req, res, next) {
            // imageVersions are taken from upload.configure()
            upload.fileHandler({
                uploadDir: function () {
                    return __dirname + '/public/uploads/' + req.sessionID
                },
                uploadUrl: function () {
                    return '/uploads/' + req.sessionID
                }
            })(req, res, next);
            // This is the added Code
            next();
        });

Are there some hooks I can do my own work?

I want to get screenshot and encode the file when I upload video.I don't find the right place to do this.
I first add some code in the 'end' event,but the operation is asynchronous too,so I can't change the fileInfo.

Moving uploaded files out of the public directory

I managed to setup the middleware with express.js 4.0 but am having difficulties moving uploaded files out of the public directory.

Here's my upload script:

    var upload = require('jquery-file-upload-middleware');
    upload.configure({
        imageVersions: {
            thumbs: {
                width: 80,
                height: 80
            },
            prev: {
                width: 1280,
                height: 1024
            }
        }
    });

    app.use('/admin/upload', function (req, res, next) {
        // imageVersions are taken from upload.configure()
        upload.fileHandler({
            uploadDir: function () {
                return __dirname + '/public/uploads/' + req.session.eventID;
            }
        })(req, res, next);

    });

Uploading a Chicken.jpg file i get the following structure:

    /public/uploads/  -> public uploads folder
        534a8d502e889f8d6bf9cc07/  -> upload session folder
            prev/  -> resized version
                Chicken.jpg
            thumbs/    -> another resized version
                Chicken.jpg
            Chicken.jpg   -> original file

I only want to move the "original file". Can anyone please advise?

Thank you!

Resize destroys photo orientation

-strip is used to remove all EXIF information, and no rotation is applied. Hence, pictures taken on a smartphone (at least an iPad or iPhone) will be rotated incorrectly.

An easy fix is to include '-auto-orient' in the imageMagick.resize() call:

                            imageMagick.resize({
                                width: opts.width,
                                height: opts.height,
                                srcPath: options.uploadDir() + '/' + fileInfo.name,
                                dstPath: options.uploadDir() + '/' + version + '/' + fileInfo.name,
                                customArgs: ['-auto-orient']
                            }, finish);

imageVersions not saving consistently

I found a strange issue when loading images with larger file size (1MB+) on my production environment. After the initial file is uploaded, only one of the imageVersions is process/saved. Also, the imageVersion that is saved is not consistent (sometimes large, sometimes small, etc.)

When testing locally everything works as expected, and all imageVersions are saved.

I have been using the example code provided with the module:

var resizeConf = require('./config').resizeVersion;
app.use('/upload/location', upload.fileHandler({
tmpDir: dirs.temp,
uploadDir: __dirname + dirs.location,
uploadUrl: dirs.location_url,
imageVersions: resizeConf.location
}));

CONSOLE OUTPUT:
files upload complete
{ name: '1MB-Picture.jpg',
originalName: '1MB-Picture.jpg',
size: 1154230,
type: 'image/jpeg',
deleteType: 'DELETE',
url: 'http://localhost:8000/uploads/location/1MB-Picture.jpg',
deleteUrl: 'http://localhost:8000/upload/location/1MB-Picture.jpg',
thumbnailUrl: 'http://localhost:8000/uploads/location/thumbnail/1MB-Picture.jpg',
smallUrl: 'http://localhost:8000/uploads/location/small/1MB-Picture.jpg',
mediumUrl: 'http://localhost:8000/uploads/location/medium/1MB-Picture.jpg',
largeUrl: 'http://localhost:8000/uploads/location/large/1MB-Picture.jpg' }

screen shot 2014-10-14 at 2 32 26 pm

But when the exact same setup on my Debian virtual machine I get this:

CONSOLE OUTPUT:
files upload complete
{ name: '1MB-Picture.jpg',
originalName: '1MB-Picture.jpg',
size: 1154230,
type: 'image/jpeg',
deleteType: 'DELETE',
url: 'http://dev.mywebsite.com/uploads/location/1MB-Picture.jpg',
deleteUrl: 'http://dev.mywebsite.com/upload/location/1MB-Picture.jpg',
mediumUrl: 'http://dev.mywebsite.com/uploads/location/medium/1MB-Picture.jpg' }

screen shot 2014-10-14 at 2 31 05 pm

Also, when I go to delete the upload and let jquery-file-upload-middleware clean up the imageVersions, I get this error:

CONSOLE OUTPUT:
files remove complete
1MB-Picture.jpg
fs: missing callback Error: ENOENT, unlink '/mywebsite/public/uploads/location/thumbnail/1MB-Picture.jpg'
fs: missing callback Error: ENOENT, unlink '/mywebsite/public/uploads/location/small/1MB-Picture.jpg'
fs: missing callback Error: ENOENT, unlink '/mywebsite/public/uploads/location/large/1MB-Picture.jpg'

When the file size is small (1KB for example), everything works as expected on the production machine.

Any idea what could be causing this? I suspect there is some race-condition with the async or fs module.

Error when upload file with new version

Hi,

Since I've update to 0.0.5 from version 0.0.1 , I've now an issue when uploading file:

events.js:66
throw arguments[1]; // Unhandled 'error' event
^
Error: ENOENT, open 'C:\tmp\6e06e9ef40fd277e5d57036897bcec5b'

Any Idea ?

Thanks.
Olivier

Question cross-domain iframe transport?

How does this handle cross-domain iframe transport. I'm only asking since I'm looking into a solution for angularjs and file upload that is supported in IE 9. I couldn't seem to find in your example one that explicitly supports that funciton of jquery-file-upload

Problem file upload with Heroku

Hello there first of all thank you so much for contribution.

I really like your library but there is one issue once I launch my website with Heroku The plugin does not worked but its work fine with Local computer.

Can anyone help me to come out, Here is my website url.
https://radiant-mesa-95812.herokuapp.com/

Thanks in advance,
Regards,
Ronak Amlani.

example

Is there an example of this posted anywhere?

i think that would be a nice addition to this. If not, I may put one together.

one file is uploaded several times

Hello

I have a weird problem, I'm working on creating a one interface to permit only load one file, it works well when I load the file for the first time, but when I load another file after deleting the previous file, this new file is uploaded twice, and then if I closed the view and open again to load a new file, the file is uploaded three times, I'm using this code to upload in the server.

app.use('/upload', function(request, response, next){
upload.fileHandler({
uploadDir: function(){
return __dirname + '/site/public/uploads/' + request.session.login;
},
uploadUrl: function(){
return '/site/uploads/' + request.session.login;
}
})(request, response, next);
upload.on('begin', function(fileInfo){
logger.debug("starting loading a file");
var ext = fileInfo.name.substr(fileInfo.name.lastIndexOf('.') + 1);
var newFile = shortId.generate() + '.' + ext;
request.session.newFile = newFile;
logger.debug("file uploaded " + request.session.newFile + " - " + newFile);
fileInfo.name = newFile;
});
upload.on('end', function(fileInfo){
logger.debug('file uploaded ' + fileInfo.name);
});
});

I would appreciate any suggestion.

Thumbs not creating

Have my upload middleware configured as usual:

upload.configure({
        uploadDir: __dirname + '/public/uploads',
        uploadUrl: '/uploads',
        imageVersions: {
            thumbs: {
                width: 80,
                height: 80
            }
        }
    });

But my thumbs folder is empty. Tried also other image version - not working. There were no code changes on upload middleware.
Using jquery-file-upload-middleware v0.1.5, node v4.1.0 and express v4.13.3
Any ideas, am I missing something?

Cannot res.send() in on End event

Using 4.31.1 - this may be my lack of understanding middleware - but is there a reason I cannot use res.send(someData) from the upload.on('end', function(){}); event??

This always generates " Error: Can't set headers after they are sent." and kills node.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.