本篇文章為大家展示了springboot中怎么接收上傳的base64圖片,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
創(chuàng)新互聯(lián)公司是專(zhuān)業(yè)的札達(dá)網(wǎng)站建設(shè)公司,札達(dá)接單;提供成都網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專(zhuān)業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行札達(dá)網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專(zhuān)業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專(zhuān)業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
@ApiOperation(value = "更新用戶(hù)信息", notes = "更新用戶(hù)信息,包括手機(jī)號(hào)、郵箱、頭像等", httpMethod = "GET") @PostMapping("/profile") public ApiResultprofile(@RequestBody SysUserVo sysUserVo) { Boolean result = false; String imageRelativePath = "static/upload"; String imageBase64Str; Integer userId = UserUtil.getUserId(request); //如果相同 if (userId > 0) { //保存頭像 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); } //更新用戶(hù)信息 result = sysUserService.updateInfoByUserId(sysUserVo); } return new ApiResult<>(result); }
上述內(nèi)容就是springboot中怎么接收上傳的base64圖片,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。