当前位置: 首页 > wzjs >正文

什么网站的易用性汕头建站程序

什么网站的易用性,汕头建站程序,建设工程有限公司是做什么的,小程序代理商在哪儿需求背景:前端调用接口,传给后台一个base64格式的数据流图片,后台需要实现解析数据流,转为图片,本地存储(测试阶段),并将URL返回给前端,前端可以通过浏览器等形式访问。前后端框架为若依spring …

需求背景:前端调用接口,传给后台一个base64格式的数据流图片,后台需要实现解析数据流,转为图片,本地存储(测试阶段),并将URL返回给前端,前端可以通过浏览器等形式访问。前后端框架为若依spring boot架构。

代码开发:

1.配置 application.yml

# Spring配置
spring:# 资源信息messages:# 国际化资源文件路径basename: i18n/messagesprofiles:active: dev# 文件上传servlet:multipart:# 单个文件大小max-file-size: 150MB# 设置总上传的文件大小max-request-size: 500MB
#设置图片保存路径
image:upload-dir: uploads/imagesaccess:base-url: http://localhost:8080/images  # 图片访问的基础URL

2.Controller中获取配置文件中的URL及基础URL路径

 

// 从配置文件中读取图片存储路径
@Value("${image.upload-dir}")
private String uploadPath;// 从配置文件中读取图片访问基础URL
@Value("${image.access.base-url}")
private String accessBaseUrl;

3. Controller中开发base64接口,包括解码、存储、拼接返回URL。

/*** 上传base64格式图片(单个)* @param request* @return*/
@PostMapping("/api/uploadImage")
public ResponseEntity<Map<String, String>> uploadImage(@RequestBody Map<String, String> request) {Map<String, String> response = new HashMap<>();try {String base64Data = request.get("image");if (base64Data == null || base64Data.isEmpty()) {response.put("error", "No image data provided");return ResponseEntity.badRequest().body(response);}// 检查并创建上传目录checkAndCreateUploadDir();// 生成唯一文件名String fileName = generateFileName();// 解码并保存图片String imageUrl = saveBase64Image(base64Data, fileName);response.put("url", imageUrl);return ResponseEntity.ok(response);} catch (Exception e) {response.put("error", "Failed to upload image: " + e.getMessage());return ResponseEntity.internalServerError().body(response);}
}/*** 加载校验图片存储地址* @throws IOException*/
private void checkAndCreateUploadDir() throws IOException {File uploadDir = new File(uploadPath);if (!uploadDir.exists()) {Files.createDirectories(Paths.get(uploadPath));}
}/*** 生成图片名* @return*/
private String generateFileName() {return IdUtils.simpleUUID() + ".jpg";
}/*** 保存图片并返回对应URL地址* @param base64Data* @param fileName* @return* @throws IOException*/
private String saveBase64Image(String base64Data, String fileName) throws IOException {// 移除Base64前缀(如果有)String base64Image = base64Data.split(",")[1];// 解码Base64数据byte[] imageBytes = Base64.getDecoder().decode(base64Image);// 保存文件String filePath = uploadPath + File.separator + fileName;try (FileOutputStream fos = new FileOutputStream(filePath)) {fos.write(imageBytes);}// 返回访问URLreturn accessBaseUrl + "/" + fileName;
}

4.配置前端可访问的服务形式,新建WebConfig

package com.ruoyi.web.core.config;import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;@Configuration
public class WebConfig implements WebMvcConfigurer {@Value("${image.upload-dir}")private String uploadPath;@Overridepublic void addResourceHandlers(ResourceHandlerRegistry registry) {registry.addResourceHandler("/images/**").addResourceLocations("file:" + uploadPath + "/");}
}

 

5.apipost测试调用

 

6.浏览器访问测试。

 

至此,该接口开发及自测完毕。


文章转载自:

http://HtfqncaQ.Lwswm.cn
http://YIsv1mH7.Lwswm.cn
http://0LcmyLML.Lwswm.cn
http://dJa37RFf.Lwswm.cn
http://mqBjirzM.Lwswm.cn
http://Nr1uUabj.Lwswm.cn
http://ABENiv1v.Lwswm.cn
http://fY1mPl9L.Lwswm.cn
http://peeRW0Rb.Lwswm.cn
http://tzuhPO0Z.Lwswm.cn
http://7IuNG5yp.Lwswm.cn
http://k610ysib.Lwswm.cn
http://ApIUQoZy.Lwswm.cn
http://KufWYO6P.Lwswm.cn
http://RNJfvX76.Lwswm.cn
http://0GTHqvKv.Lwswm.cn
http://SeiNhsXw.Lwswm.cn
http://SmLjBqPf.Lwswm.cn
http://5JZxKwaH.Lwswm.cn
http://63ocNiom.Lwswm.cn
http://qraPzIqg.Lwswm.cn
http://BT5tVa5X.Lwswm.cn
http://XibOYGox.Lwswm.cn
http://d6HljaaQ.Lwswm.cn
http://1mHwqVz4.Lwswm.cn
http://gcopJjo6.Lwswm.cn
http://OURFDfaI.Lwswm.cn
http://WbfH4OwR.Lwswm.cn
http://429zekQA.Lwswm.cn
http://Fc94HGt9.Lwswm.cn
http://www.dtcms.com/wzjs/618140.html

相关文章:

  • 南宁网站建设蓝云手机网站图片轮播
  • 湛江专业的建站托管上市公司做网站有什么用
  • 个人网站开发赚钱方向wordpress在线咨询
  • 顶呱呱集团 网站建设微网站的好处
  • 中国有多少网站有多少域名新网站建设银行提升转账额度
  • 冀州网站建设linux主机上传网站
  • 嘉兴seo网站建设网站网站开发的公司电话
  • 太原网站建设策划中卫平面设计师招聘
  • 郑州高端定制网站社交系统开发
  • 福州seo推广seo点击软件排名优化
  • 西安公司的网站建设东莞常平镇邮政编码
  • 100m网站注册wordpress设置固定链接后
  • 郑州模板网站设计哪家便宜wordpress界面菜单怎么弄
  • 东莞网络营销型网站做违法网站的后果
  • 垄断了网站建设wordpress官网上的主题收费吗
  • 招聘网站开发计划书百度知道官网手机版
  • 台州网站推广福泉网站制作
  • 网站制作需要多少钱品牌wordpress外观插件
  • 遂昌建设局网站上海网络公司网站
  • 项目网络图经常被称为做seo要明白网站内容
  • 做抽纸行业网站亚马逊雨林的动物
  • 专业平台建设网站关了吗做网站需要展示工厂么?
  • 陕西公路工程建设有限公司网站外发加工平台
  • 太原做手机网站设计网页设计与制作学什么
  • 2017做哪些网站致富中国网络安全公司排名
  • 做网站样品图片怎么拍照网站建设期末题答案
  • 网站建设时间进度表模板wordpress 分类目录 页面
  • 公司外贸网站建设房地产公司排名前十
  • 网站推广计划至少应包括wordpress woo theme
  • 百度一下建设部网站全网模板建站系统