Node与Express开发未解决问题 之8.8 jQuery文件上传
meadowlark.js部分
var jqupload = require('jquery-file-upload-middleware'); app.use('/upload',function(req,res,next){ var now = Date.now(); jqupload.fileHandler({ uploadDir:function(){ console.log('win'); return __dirname + '/public/uploads/' + now; }, uploadUrl:function(){ console.log('/uploads/'+now); return '/uploads/' + now; }, })(req,res,next); });
相关代码
<!--// 图片上传成功列表未能显示 尚待解决 <span class="btn btn-default btn-file"> Upload <input type="file" class="form-control" required accept="image/*" id="fieldPhoto" data-url="/upload" multiple name="photo"> </span> <div id="uploads"></div> {{#section 'jquery'}} <script src="/vendor/jqfu/js/vendor/jquery.ui.widget.js"></script> <script src="/vendor/jqfu/js/jquery.iframe-transport.js"></script> <script src="/vendor/jqfu/js/jquery.fileupload.js"></script> <script> $(document).ready(function(){ $('#fieldPhoto').fileupload({ dataType:'json', done:function(e,data){ $.each(data.result.files,function(index,file){ $('#fileUploads').append($('<div class="upload">' + '<span class="glyphicon glyphicon-ok"></span>' + ' ' + file.originalName + '</div>' )); }); } }); }); </script> {{/section}} -->
程序执行界面
图片上传界面
仅仅留给自己笔记 大神不要嫌弃