项目要发送多图微博,
根据微博API打算利用后台拼接multipart/form-data请求
有没有大神能能教教如何拼接这个请求
这是springmvc结构的图片上传,用拼串的方式实现多图上传,输出时在进行截串进行显示
@RequestMapping("")
public String insert(@RequestParam MultipartFile[] up, User u,
HttpServletRequest request) throws IllegalStateException,
IOException {
String s = "";
if (up != null && up.length != 0) {
for (MultipartFile file : up) {
if (file != null && file.getSize() != 0) {
// String parent=request.getRealPath("up");
String parent = request.getSession().getServletContext()
.getRealPath("images");
System.out.println("realpath");
String child = file.getOriginalFilename(); // 获取上传时选择的图片的名称
File destFile = new File(parent, child);
file.transferTo(destFile);
if (up.length == 1) {
s = child;
} else {
s += child + ",";
}
}
}
}
u.setPhoto(s);
userdao.insertuser(u);
return "forward:/user/select";
}