需求是选择相册,然后上传图片到相册。 app.js,使用multer
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));
页面
<form id="form" method="post" action="/upload" >
<p>
<span >选择相册:</span>
<select name="album">
<%
var albumValue = albums[0]._id;
if (typeof(album) !== 'undefined') {
albumValue = album;
}
albums.forEach(function (album) {
console.log(album);
var albumId = album._id;
var albumName = album.name;
%>
<option value="<%=albumId%>" <%= albumValue === albumId ? 'selected': '' %>><%=albumName%></option>
<%});%>
</select>
</p>
<div id="uploader">
<p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
</div>
<br />
</form>
后端:
exports.upload = function (req, res){
console.log("req.body:"+JSON.stringify(req.body));
};
log: POST /upload - - ms - - req.body:{"name":"Chrysanthemum.jpg","chunk":"0","chunks":"1"}
问题是后端如何获取下拉框选中的album的信息呢?
6 回复
@inosqlorg 用formdata装你要提交的数据,包括文件信息和其他数据。 例如: var data = new FormData(); var files = $(“#thumbnail”)[0].files; if (files) { data.append("thumbnail", files[0]); } data.append("startTime", $(“#txtStart”).val()); data.append("endTime", $(“#txtEnd”).val());