Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert MultipartFile to File when SpringMVC uploads a file

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report