我在用着值 ajax 文件上传器 http://valums.com/ajax-upload/
我的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 分钟后,它就会显示出来,甚至不需要刷新页面。是什么导致了这种行为?是管道的问题,我需要打电话给马里奥来修理它还是其他什么? :)