在Safari中将文件上载到Express.js服务器失败

时间:2012-12-07 12:14:23

标签: ajax node.js safari express valums-file-uploader

我使用ajax Valum的qq上传器(https://github.com/valums/file-uploader)将图片上传到Express.js(3.0.0)服务器。它适用于所有流行的浏览器,但Safari。 发生以下错误:

TypeError:无法读取未定义的属性“length”     在推广(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/node_modules/qs/lib/querystring.js:15:18)     at parse(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/node_modules/qs/lib/querystring.js:53:58)     at parse(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/node_modules/qs/lib/querystring.js:50:7)     在合并时(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/node_modules/qs/lib/querystring.js:68:5)     at String.split.reduce.base(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/node_modules/qs/lib/querystring.js:111:14)     在Array.reduce(本机)     at parseString(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/node_modules/qs/lib/querystring.js:101:6)     at Object.exports.parse(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/node_modules/qs/lib/querystring.js:127:7)     在IncomingMessage.module.exports(/home/andrew/projects/dreamshare-git/src/main/node_modules/express/node_modules/connect/lib/middleware/urlencoded.js:66:18)     在IncomingMessage.EventEmitter.emit(events.js:90:17)

请告知任何解决方案?谢谢!

1 个答案:

答案 0 :(得分:0)

好的,我们在深入了解express.js内部后对它进行了排序。问题是旧版本的文件上传器没有设置上传文件的类型,Safari将其设置为默认的普通帖子,因此express.js错误地将其处理为普通邮件查询。解决方案是更新上传库。其中以下行正确设置了内容类型:

xhr.setRequestHeader("Content-Type", file.type);