Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileInfo class lack file.path when used in local.js #58

Open
SamBlakeKing opened this issue Dec 22, 2016 · 2 comments
Open

FileInfo class lack file.path when used in local.js #58

SamBlakeKing opened this issue Dec 22, 2016 · 2 comments

Comments

@SamBlakeKing
Copy link

when I use it for big files upload, I meet a issue about the request of "/update". Fallow the tutorial, there is my code on server.

# uploade.js
var options = {
    tmpDir:  __dirname + '/../public/points/tmp',
    uploadDir: __dirname + '/../public/points/files',
    uploadUrl:  '/pointsupload/uploaded/files/',
    storage : {
        type : 'local'
    }
};

var uploader = require('blueimp-file-upload-expressjs')(options);

router.get('/', function (req, res, next) {
    res.render('pointsupload');
});

router.get('/upload', function (req, res) {
    uploader.get(req, res, function (err, obj) {
        if(!err){
            res.send(JSON.stringify(obj));
        }
    });
});

router.post('/upload', function (req, res) {
    uploader.post(req, res, function (err, obj) {
        if(!err){
            res.send(JSON.stringify(obj));
        }
    });
});

router.delete('/uploaded/files/:name', function (req, res) {
    uploader.delete(req, res, function (err, obj) {
        if(!err){
            res.send(JSON.stringify(obj));
        }
    });
});

# app.js
var pointsupload = require('./routes/pointsupload');
app.use('/pointsupload', pointsupload);

When I enter "http: localhost:XX/pointsupload/upload" on the browser, I get some errors as follow.

path.js:7
    throw new TypeError('Path must be a string. Received ' + inspect(path));
    ^

TypeError: Path must be a string. Received undefined
    at assertPath (path.js:7:11)
    at Object.basename (path.js:799:5)
    at getFileKey (D:\Tom\share\pointCloud\node_modules\blueimp-file-upload-expressjs\lib\fileinfo.js:12:17)
    at new FileInfo (D:\Tom\share\pointCloud\node_modules\blueimp-file-upload-expressjs\lib\fileinfo.js:24:16)
    at D:\Tom\share\pointCloud\node_modules\blueimp-file-upload-expressjs\lib\transport\local.js:24:40
    at Array.forEach (native)
    at D:\Tom\share\pointCloud\node_modules\blueimp-file-upload-expressjs\lib\transport\local.js:21:22
    at FSReqWrap.oncomplete (fs.js:123:15)

so I views the source of local.js and fileinfo.js. On 15:37 of local.js, It use FileInfo class which is defined on fileinfo.js, but it didn't define the "path" param.

get: function(callback) {
            var files = [],
                options = this.options;
            // fix #41
            options.saveFile = false;
            fs.readdir(options.uploadDir, function(err, list) {
                list.forEach(function(name) {
                    var stats = fs.statSync(options.uploadDir + '/' + name);
                    if (stats.isFile() && name[0] !== '.') {
                        var fileInfo = new FileInfo({
                            name: name,
                            size: stats.size,
                            lastMod: stats.mtime
                        }, options);
                        fileInfo.initUrls();
                        files.push(fileInfo);
                    }
                });
                callback(null, {
                    files: files
                });
            });
        },

but In the source of fileinfo.js, FileInfo class need file param has path property and getFileKey function use it.

function FileInfo(file, opts, fields) {
    this.name = file.name;
    this.size = file.size;
    this.type = file.type;
    this.modified = file.lastMod;
    this.deleteType = 'DELETE';
    this.options = opts;
    this.key = getFileKey(file.path);
    this.versions = {};
    this.proccessed = false;
    this.width = udf;
    this.height = udf;
    this.fields = fields;
    if (opts.saveFile) {
        this.safeName();
    }
}
@RagaMaga
Copy link

this.name = file.name;
this.size = file.size;
this.type = file.type;
this.modified = file.lastMod;
this.deleteType = 'DELETE';
this.options = opts;
this.key                = (file.path === undefined ? '' :  getFileKey(file.path));
this.versions = {};
this.proccessed = false;
this.width = udf;
this.height = udf;
this.fields = fields;
if (opts.saveFile) {
    this.safeName();
}

@ldarren
Copy link

ldarren commented May 18, 2018

i had similar problem, and i have it fixed in my fork https://github.com/ldarren/blueimp-file-upload-expressjs

side note, in my fork the s3 upload is fully working with thumbnail

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants