我使用valums ajax file-uploaderValums文件上传 - 多文件上传
我的NodeJS服务器端是这样的:
fileStream = fs.createWriteStream(__dirname+'/../public/images/houses/'+rndname);
req.pipe(fileStream);
req.on('end', function() {
body = '{"success":"true", "name": "'+rndname+'"}';
res.writeHead(200,
{ 'Content-Type':'text/plain'
, 'Content-Length':body.length
});
res.end(body);
});
客户端:
function createUploader(){
var uploader = new qq.FileUploader({
element: document.getElementById('homepic'),
action: '/server/upload',
allowedExtensions: ['jpg', 'png', 'gif'],
multiple:true,
onComplete: function(id, fileName, responseJSON){
$("#homepic").append("<img src='/images/houses/"+responseJSON.name+"' class='mediumpic' /> ");
}
});
}
window.onload = createUploader;
这一切工作单个文件上传很棒!
所以想象 - 我按上传按钮,选择图片,它上传真的很快,显示在屏幕上。 现在我想上传另一个。我选择图片,它在服务器上快速上传(我在服务器上看到它),我得到新文件名和成功的响应,我把图片放在屏幕上,并附上我的附件。但图片没有显示出来。我尝试在新标签中打开图片,尽管我在站在右侧的服务器上看到它仍然没有。等待3-5分钟后,它就会显示出来,甚至不需要刷新页面。什么导致这种行为?这是管道,我需要打电话给马里奥修理它或其他东西? :)
按照[GitHub的页面(https://开头github.com/valums/file-uploader)这个项目已经转移到http://fineuploader.com/上面的链接中断。 – Sukima