How to convert MultipartFile to File when SpringMVC uploads a file
This article mainly explains "how to convert SpringMVC upload file MultipartFile to File". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "SpringMVC upload file MultipartFile how to File" it!
MultipartFile to File
File file = new File (mFile.getOriginalFilename ()); FileUtils.copyInputStreamToFile (mFile.getInputStream (), file); / / temporary files will be generated locally, and if (file.exists ()) {file.delete ();} needs to be deleted after use.
MultipartFile acquires Base64 code
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 ();}}
At this point, I believe that everyone on the "SpringMVC upload file MultipartFile how to File" have a deeper understanding, might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!