@RequestMapping("/get/uploadPhoto.do") public void saveFile(HttpServletResponse response, HttpSession session, MultipartHttpServletRequest multipartRequest) { MultipartFile mFile = multipartRequest.getMultiFileMap().getFirst("Filedata"); File file = null; try { file=File.createTempFile("tmp", null); mFile.transferTo(file); file.deleteOnExit(); //使用完成删除文件 } catch (HttpException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } InputStream in = null; byte[] data = null; //读取图片字节数组 try { in = new FileInputStream(file); data = new byte[in.available()]; in.read(data); in.close(); } catch (IOException e) { e.printStackTrace(); } String base64Str=new String(Base64.encodeBase64(data)); }
上传图片转换为base64
最新推荐文章于 2024-08-01 16:02:21 发布