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

网站设计方法男女做暖暖的网站大全

网站设计方法,男女做暖暖的网站大全,网站带做收录排名,高清的网站制作背景 在业务中我们往往需要上传文件如图片#xff0c;文件上传#xff0c;是指将本地图片、视频、音频等文件上传到服务器上#xff0c;可以供其他用户浏览或下载的过程。文件上传在项目中应用非常广泛#xff0c;我们经常发抖音、发朋友圈都用到了文件上传功能。 实现文件…背景 在业务中我们往往需要上传文件如图片文件上传是指将本地图片、视频、音频等文件上传到服务器上可以供其他用户浏览或下载的过程。文件上传在项目中应用非常广泛我们经常发抖音、发朋友圈都用到了文件上传功能。 实现文件上传服务需要有存储的支持那么我们的解决方案将以下几种 直接将图片保存到服务的硬盘springmvc中的文件上传 优点开发便捷成本低缺点扩容困难 使用分布式文件系统进行存储 优点容易实现扩容缺点开发复杂度稍大有成熟的产品可以使用比如FastDFS,MinIO 使用第三方的存储服务例如OSS 优点开发简单拥有强大功能免维护缺点付费 1.定义OSS相关配置 application-dev.yml sky:alioss:endpoint: oss-cn-hangzhou.aliyuncs.comaccess-key-id: LTAI5tPeFLzsPPT8gG3LPW64access-key-secret: U6k1brOZ8gaOIXv3nXbulGTUzy6Pd7bucket-name: sky-take-outapplication.yml spring:profiles:active: dev #设置环境 sky:alioss:endpoint: ${sky.alioss.endpoint}access-key-id: ${sky.alioss.access-key-id}access-key-secret: ${sky.alioss.access-key-secret}bucket-name: ${sky.alioss.bucket-name} 2). 读取OSS配置 在sky-common模块中已定义 package com.sky.properties;import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Component ConfigurationProperties(prefix sky.alioss) Data public class AliOssProperties {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName;}3). 生成OSS工具类对象 在sky-server模块 package com.sky.config;import com.sky.properties.AliOssProperties; import com.sky.utils.AliOssUtil; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;/*** 配置类用于创建AliOssUtil对象*/ Configuration Slf4j public class OssConfiguration {BeanConditionalOnMissingBeanpublic AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){log.info(开始创建阿里云文件上传工具类对象{},aliOssProperties);return new AliOssUtil(aliOssProperties.getEndpoint(),aliOssProperties.getAccessKeyId(),aliOssProperties.getAccessKeySecret(),aliOssProperties.getBucketName());} }其中AliOssUtil.java已在sky-common模块中定义 package com.sky.utils;import com.aliyun.oss.ClientException; import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSException; import lombok.AllArgsConstructor; import lombok.Data; import lombok.extern.slf4j.Slf4j; import java.io.ByteArrayInputStream;Data AllArgsConstructor Slf4j public class AliOssUtil {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName;/*** 文件上传** param bytes* param objectName* return*/public String upload(byte[] bytes, String objectName) {// 创建OSSClient实例。OSS ossClient new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);try {// 创建PutObject请求。ossClient.putObject(bucketName, objectName, new ByteArrayInputStream(bytes));} catch (OSSException oe) {System.out.println(Caught an OSSException, which means your request made it to OSS, but was rejected with an error response for some reason.);System.out.println(Error Message: oe.getErrorMessage());System.out.println(Error Code: oe.getErrorCode());System.out.println(Request ID: oe.getRequestId());System.out.println(Host ID: oe.getHostId());} catch (ClientException ce) {System.out.println(Caught an ClientException, which means the client encountered a serious internal problem while trying to communicate with OSS, such as not being able to access the network.);System.out.println(Error Message: ce.getMessage());} finally {if (ossClient ! null) {ossClient.shutdown();}}//文件访问路径规则 https://BucketName.Endpoint/ObjectNameStringBuilder stringBuilder new StringBuilder(https://);stringBuilder.append(bucketName).append(.).append(endpoint).append(/).append(objectName);log.info(文件上传到:{}, stringBuilder.toString());return stringBuilder.toString();} }4). 定义文件上传接口 在sky-server模块中定义接口 package com.sky.controller.admin;import com.sky.constant.MessageConstant; import com.sky.result.Result; import com.sky.utils.AliOssUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; import java.util.UUID;/*** 通用接口*/ RestController RequestMapping(/admin/common) Api(tags 通用接口) Slf4j public class CommonController {Autowiredprivate AliOssUtil aliOssUtil;/*** 文件上传* param file* return*/PostMapping(/upload)ApiOperation(文件上传)public ResultString upload(MultipartFile file){log.info(文件上传{},file);try {//原始文件名String originalFilename file.getOriginalFilename();//截取原始文件名的后缀 dfdfdf.pngString extension originalFilename.substring(originalFilename.lastIndexOf(.));//构造新文件名称String objectName UUID.randomUUID().toString() extension;//文件的请求路径String filePath aliOssUtil.upload(file.getBytes(), objectName);return Result.success(filePath);} catch (IOException e) {log.error(文件上传失败{}, e);}return Result.error(MessageConstant.UPLOAD_FAILED);} }
http://www.w-s-a.com/news/329722/

相关文章:

  • 怎么自己做网站地图网站建设弹窗代码
  • wordpress 作品集网站企业做网站建设的好处
  • 公司开发的网站健身网站开发项目总结
  • 怎样做游戏网站网站建设万首先金手指14
  • 英德建设局网站龙岩网上房地产网
  • wordpress vr网站电影网页设计尺寸
  • 做淘宝客新增网站推广怎样开一家公司
  • 企业网站有必要做吗?网站平均停留时间
  • 蘑菇街的网站建设凡科网站建设网页怎么建
  • 中国光大国际建设工程公司网站论坛是做网站还是app好
  • 地产集团网站建设高德是外国公司吗?
  • 天津市网站建站制作网站建设新报价图片欣赏
  • 怎么样在百度搜到自己的网站高端房产网站建设
  • 邯郸做移动网站多少钱ui设计好就业吗
  • 共享虚拟主机普惠版做网站产品推广包括哪些内容
  • 广州市网站建站免费咨询医生有问必答
  • app网站建设制作哪个网站可以做魔方图片
  • 教育培训网站建设方案模板下载网站文风
  • 电龙网站建设wordpress文章两端对齐
  • 做外单网站亚马逊免费的网站加速器
  • 英文网站推广工作一个虚拟主机可以做几个网站吗
  • 微网站 合同重庆电力建设设计公司网站
  • 网站怎么设置支付网站源码下载后怎么布置
  • 广州市公需课在哪个网站可以做手机商城软件下载
  • app网站建设需要什么长治网站建设公司
  • 网站模板平台广告宣传网站
  • cc域名的网站做网站放太多视频
  • 让公司做网站要注意什么建设工程公司企业文化
  • 佛山搭建建网站哪家好微信如何建立自己的公众号
  • 联想公司网站建设现状广州建网站兴田德润团队