blueimp-file-upload-expressjs
blueimp-file-upload-expressjs copied to clipboard
FileInfo class lack file.path when used in local.js
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();
}
}
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();
}
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