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

江门阿里巴巴网站建设wordpress样式多的编辑器

江门阿里巴巴网站建设,wordpress样式多的编辑器,宁陵做网站,闸北企业网站建设文件上传流程#xff1a; 创建阿里云OSS#xff08;对象存储服务#xff09;的bucket 登录阿里云#xff0c;并完成实名认证#xff0c;地址#xff1a;https://www.aliyun.com/. 可以通过搜索#xff0c;进入以下页面#xff1a; 点击立即使用后#xff1a; 点击…文件上传流程 创建阿里云OSS对象存储服务的bucket 登录阿里云并完成实名认证地址https://www.aliyun.com/. 可以通过搜索进入以下页面 点击立即使用后 点击试用后就开通了相关服务然后在产品中搜索“OSS”点击管理平台 点击“Bucket列表”进行创建 代码 创建成功后再次进入bucket列表通过帮助文档进入到SDK选择Java 也可以使用以下文件上传代码示例 代码思路 配置文件中 (application-dev.xml) 添加OSS的配置项可以通过配置属性类AliOssProperties加载并封装这些属性值然后通过OssConfiguration创建AliOssProperties其中OssConfiguration在项目启动时就能调用aliOssUtil方法把该对象创建出来后交给spring容器进行管理通过Bean实现ConditionalOnMissingBean保证整个spring容器里面只有一个AliOssUtil对象因此可以在对应的Controller类中通过Autowired获取到AliOssUtil实现文件上传。 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();} } 相关配置项的设置: 设置配置属性类 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;} 项目配置文件设置application.xml server:port: 8080spring:profiles:active: devmain:allow-circular-references: truedatasource:druid:driver-class-name: ${sky.datasource.driver-class-name}url: jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezoneAsia/ShanghaiuseUnicodetruecharacterEncodingutf-8zeroDateTimeBehaviorconvertToNulluseSSLfalseallowPublicKeyRetrievaltrueusername: ${sky.datasource.username}password: ${sky.datasource.password}mybatis:#mapper配置文件mapper-locations: classpath:mapper/*.xmltype-aliases-package: com.sky.entityconfiguration:#开启驼峰命名map-underscore-to-camel-case: truelogging:level:com:sky:mapper: debugservice: infocontroller: infosky:jwt:# 设置jwt签名加密时使用的秘钥admin-secret-key: itcast# 设置jwt过期时间admin-ttl: 7200000# 设置前端传递过来的令牌名称admin-token-name: token# 添加阿里云文件存储服务相关配置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}这里使用变量的方式添加阿里云对象存储服务的相关属性值以便适应开发(dev)和产品(prod)两种环境当前使用的环境为dev于是在application-dev.xml中设置相关属性值如 sky:datasource:driver-class-name: com.mysql.cj.jdbc.Driverhost: localhostport: 3306database: xxxxusername: rootpassword: xxxxalioss:endpoint: oss-cn-hangzhou.aliyuncs.comaccess-key-id: xxxxaccess-key-secret: xxxxbucket-name: xxxx添加OSS配置类 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;/*** ClassName: OssConfig* PackageName: com.sky.config* Description: 配置类用于创建AliOssUtil对象** Author Xiyan Zhong* Create 2023/12/19 下午4:35* Version 1.0*/ Configuration Slf4j public class OssConfiguration {BeanConditionalOnMissingBeanpublic AliOssUtil aliOssUtil(AliOssProperties aliOssProperties) {log.info(开始创建阿里云文件上传工具类对象{},aliOssProperties);return new AliOssUtil(aliOssProperties.getEndpoint(),aliOssProperties.getAccessKeyId(),aliOssProperties.getAccessKeySecret(),aliOssProperties.getBucketName());} } 相应的controller代码 package com.sky.controller.admin;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;/*** ClassName: CommonController* PackageName: com.sky.controller.admin* Description:通用上传接口** Author Xiyan Zhong* Create 2023/12/19 下午2:46* Version 1.0*/RestController RequestMapping(/admin/common) Api(tags 通用接口) Slf4j public class CommonController {// 通过Autowired注解注入依赖Autowiredprivate AliOssUtil aliOssUtil;/*** 文件上传* param file* return*/PostMapping(/upload)ApiOperation(文件上传)// 参数名要与前端请求时的参数保持一致public ResultString upload(MultipartFile file){log.info(文件上传{},file);try {// 获取原始文件名String originalFileName file.getOriginalFilename();// 截取原始文件名的后缀String extension originalFileName.substring(originalFileName.lastIndexOf(.));// 构造新文件名称String objectName UUID.randomUUID().toString() extension;// 第一个参数文件对象转成的字节数组第二个参数文件上传到OSS中对应的名称通过UUID后缀生成避免文件重名导致文件覆盖。// filePath表示文件的请求路径String filePath aliOssUtil.upload(file.getBytes(),objectName);return Result.success(filePath);}catch (IOException e){log.error(文件上传失败{},e);}return Result.error(文件上传失败);} }
http://www.hkea.cn/news/14281417/

相关文章:

  • 自己的网站怎么做seo制作网站公司推荐
  • 别人做的网站怎么seo优化地方网站推广
  • 手机创建个人网站 免费郑州外贸网站建设公司价格
  • 怎么样在服务器上建设网站2012年网站设计方法
  • 有没有专门做印刷图的网站网站做app用什么语言
  • 环保网站 中企动力建设在线识别图片来源
  • html5网站链接标签wordpress 表结构
  • 商洛做网站的公司免备案域名直购
  • 网站开发需要什么基础网站开发 行业动态
  • 网站建站哪家公司好一点网站建设的经验做法
  • 中山网站seo关键词专业江西网站建设
  • 网站建设原理上海品牌营销咨询公司
  • 网站制作的方法搜索引擎优化的报告
  • 网站建设宣传册内容广东省住房建设厅网站6
  • 网站实现多语言在中国如何推广外贸平台
  • 苏州建网站的公司一站式服务公司WordPress添加前台投稿
  • 百度智能建站系统甘肃网站建设选哪家
  • 简洁大气网站模板宁波优化推广选哪家
  • 帮人做彩票网站有事吗企业crm软件
  • 在対网站做可能的来自内部和外部的攻击2023最近爆发的流感叫什么
  • 大型网站系统网站建设国内外研究现状模板
  • 网站录屏可以做证据吗中山网站建设文化机构
  • 东台网站建设服务商pr软件
  • 网站开发维护的工作职责乌海seo公司
  • 内部优惠券网站建站阳澄湖大闸蟹网站建设
  • 淮南学校网站建设电话宁波seo关键词培训
  • 一键生成作文的网站网站建设工作室 需要营业执照吗
  • 网站转化微信小程序成都哪家公司做网站比较好
  • 宁波网站建设与维护新产品开发流程和步骤
  • 企业 网站备案app开发公司有前景么