In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to receive uploaded base64 pictures in springboot. The content is concise and easy to understand, which will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
@ ApiOperation (value = "update user information", notes = "update user information, including mobile phone number, mailbox, avatar, etc.", httpMethod = "GET") @ PostMapping ("/ profile") public ApiResult profile (@ RequestBody SysUserVo sysUserVo) {Boolean result = false; String imageRelativePath = "static/upload"; String imageBase64Str; Integer userId = UserUtil.getUserId (request) / / if the same if (userId > 0) {/ / Save avatar StringBuffer fileName = new StringBuffer (); fileName.append (UUID.randomUUID (). ToString (). ReplaceAll ("-", ")); if (StringUtils.isBlank (sysUserVo.getAvatar () {return new ApiResult (false) } else if (sysUserVo.getAvatar (). IndexOf (_ "data:image/png;")! =-1) {imageBase64Str = sysUserVo.getAvatar (). Replace ("data:image/png;base64,", "); fileName.append (" .png ");} else if (sysUserVo.getAvatar (). IndexOf (_" data:image/jpeg) ")! =-1) {imageBase64Str = sysUserVo.getAvatar () .replace (" data:image/jpeg;base64, ","); fileName.append (".jpeg");} else {return new ApiResult (false);} File path Try {path = new File (ResourceUtils.getURL ("classpath:"). GetPath (); if (! path.exists ()) {path = new File ("");} File uploadPath = new File (path.getAbsolutePath (), imageRelativePath) If (! uploadPath.exists ()) {uploadPath.mkdirs ();} String relativeFile = imageRelativePath+ "/" + fileName.toString (); File file = new File (uploadPath, fileName.toString ()); byte [] fileBytes = Base64.getDecoder () .decode (imageBase64Str); FileUtils.writeByteArrayToFile (file, fileBytes) SysUserVo.setUserId (userId); sysUserVo.setAvatar (relativeFile);} catch (FileNotFoundException e) {e.printStackTrace ();} catch (IOException e) {e.printStackTrace (); return new ApiResult (false) } / / Update user information result = sysUserService.updateInfoByUserId (sysUserVo);} return new ApiResult (result);} the above content is how to receive uploaded base64 images in springboot. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.