File file = new File(mFile.getOriginalFilename()); FileUtils.copyInputStreamToFile(mFile.getInputStream(), file); // 会在本地产生临时文件,用完后需要删除 if (file.exists()) { file.delete(); }
MultipartFile 获取 Base64 编码
File file = new File(mFile.getOriginalFilename()); FileUtils.copyInputStreamToFile(mFile.getInputStream(), file); try (FileInputStream fis = new FileInputStream(file)) { byte[] buf = new byte[(int) file.length()]; fis.read(buf); return new String(Base64.encodeBase64(buf), StandardCharsets.ISO_8859_1); } catch (IOException e) { log.error(e.getMessage(), e); } finally { if (file.exists()) { file.delete(); } }
站长微信:xiaomao0055
站长QQ:14496453