代码在桌面上工作正常,但我认为它在移动设备上超时。我还是节点新手。用express和busboy写在nodejs中。下面的代码显示了我如何处理从表单发布的图像。在移动浏览器加载一段时间后,只需重新加载表单。在桌面上处理正常。其他人遇到过这个问题吗?我有什么想法吗?
router.post('/', function (req, res){
var busboy = new Busboy({ headers: req.headers });
busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
//name the file uploaded
var file_name = Math.round(Math.random()*1000) + '.jpg';
//store the path of the uploaded file
var saveTo = 'public/images/uploads/' + file_name;
file.pipe(fs.createWriteStream(saveTo));
});
busboy.on('finish', function() {
res.redirect('back');
});
return req.pipe(busboy);
});
HTML表格张贴图片(从我的手机添加,抱歉,如果它有点粗糙)
<form class="form-inline" action="/" enctype="multipart/form-data" method="post">
<div class="form-group">
<input type="file" id="upload" name="upload">
</div>
<div class="form-group">
<button type="submit" class="btn btn-default">Find</button>
</div>
</form>