我怎样才能得到的byte []来源:字节[]从Spring MVC中输入文件
< input type="file" value="${restaurant.logo }" name="logo" /> in Spring MVC?
我想有byte []数组将其转换为base64。但我不知道如何简单地将文件从输入转换为字节[]。
我怎样才能得到的byte []来源:字节[]从Spring MVC中输入文件
< input type="file" value="${restaurant.logo }" name="logo" /> in Spring MVC?
我想有byte []数组将其转换为base64。但我不知道如何简单地将文件从输入转换为字节[]。
<form action="uploadLogo">
<input type="file" ... />
</form>
然后在@Controller
@RequestMapping("/uploadLogo")
public String uploadLogo(@RequestParam MultipartFile logo) {
byte[] bytes = logo.getBytes();
String base64 = new String(Base64.encodeBase64(bytes), "ISO-8859-2");
}
(Base64是的commons-codec一部分)
查看org.springframework.web.multipart.MultipartFile,它可以打包上传文件,并具有getBytes()
方法将文件内容返回为byte[]
。
如果您真的想要,您还可以将byte[]
字段绑定到上传的文件 - 只需将ByteArrayMultipartFileEditor注册为活页夹的自定义编辑器。
如何与MultiActionAndView功能做到这一点?我: >公开的ModelAndView myrestaurantadd(HttpServletRequest的请求, > \t \t \t HttpServletResponse的响应,餐厅>餐厅) – zax 2011-05-22 07:45:34
只是方法参数追加到其余 – Bozho 2011-05-22 07:50:19
当我把requestparam到我的论点,我得到了错误:无法实例豆class [org.springframework.web.multipart.MultipartFile]:指定的类是一个接口 – zax 2011-05-22 08:02:50