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

洛阳建设部官方网站与安网站建设

洛阳建设部官方网站,与安网站建设,高端网站建设合同,wordpress转程序阿里云官网#xff1a;阿里云-计算#xff0c;为了无法计算的价值 通过阿里云官网#xff0c;登录进入用户的界面#xff0c;在搜索框中输入OSS#xff0c;然后进入阿里云的对象存储OSS的控制台。#xff08;未开通的开通即可#xff09; 创建 Bucket 点击【Bucket 列…阿里云官网阿里云-计算为了无法计算的价值 通过阿里云官网登录进入用户的界面在搜索框中输入OSS然后进入阿里云的对象存储OSS的控制台。未开通的开通即可 创建 Bucket 点击【Bucket 列表】查看个人的Bucket。点击【创建 Bucket】创建新的 Bucket。其中必填项有 Bucket 名称唯一的就行地域选择一个近的就行例如华南1深圳存储类型选择【标准存储】读写权限选择【公共读】其他选项默认 点击【确定】即可创建。 上传文件 可以通过【文件管理】中【文件列表】进行上传文件 点击【上传文件】即可上传指定文件到OSS中。 选择上传文件步骤如图。除了上传文件外还可以上传文件夹。 点击【上传文件】后通过【任务列表】可以查看上传的文件情况。 之后可以在【文件列表】中查看上传的文件且可以点击【详情】查看文件的信息。 在【详情】中可以注意到文件有一个URL地址我们可以通过这个地址下载该文件。 配置RAM用户 如果想要在开发中进行操作阿里云OSS云存储的文件那么需要配置 RAM。配置的具体操作如下。 点击【账户头像】找到【AccessKey 管理】。 生成用户的【AccessKey ID】和【AccessKey Secret】。这里需要将其记住以便后面开发中使用。 定义OSS相关配置 sky:alioss:endpoint: oss-cn-hangzhou.aliyuncs.com根据自己情况填写access-key-id: *************根据自己情况填写access-key-secret: **********根据自己情况填写bucket-name: sky-take-out-zhangxi根据自己情况填写读取OSS配置 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;}生成OSS工具类对象 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如下 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();} }在server模块中定义文件上传接口 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.sadfv.cn/news/289932/

相关文章:

  • 效果图网站排行榜前十名wordpress列表页
  • 寻找哈尔滨网站建设wordpress文章末尾添加版权声明
  • 广州网站建设企业做网站办公照片
  • 沈阳网站公司哪个好视频分享网站建设
  • 长沙建设局网站单位有公网ip怎么做网站
  • 长沙做网站推广哪家好网页游戏传奇霸主攻略
  • 自学网站建设教程家庭网站建设
  • 邓州网站制作网站模型怎么做的
  • 金华网站建设公司哪家好什么是网站程序
  • 网站推广策划案格式及范文wan网站建设
  • 做设计找图有哪些网站有哪些问题区块链网站开发资金
  • 广东建设安全协会网站企业形象宣传策划方案
  • 保定seo网站排名做任务领礼品的网站
  • 怎么做英文版的网站企业网站下周
  • 安徽长江建设集团有限公司网站深圳全网推广推荐
  • 网站设计客户对接流程用vps刷网站流量要怎么做
  • 平面设计软件大全免费福州百度快速优化
  • 南京小程序网站开发黄页88网能不能发免费的广告
  • 台州网站制作维护免费下载代码项目的网站
  • 怎么选择模板建站服务山西seo排名厂家
  • jquery动画特效网站php 公司网站
  • 做网站之前的前期中国建设银行幼儿缴费官网站
  • 站长聚集地提高网站建设管理水平
  • 网站优化工具升上去济南seo外包服务
  • html5可以做手机网站吗创建一个网站的创业计划书
  • 做网络课堂的平台有哪些网站个人承接网站开发
  • 网站开发用不用写交互百度对网站的收录
  • 挂马网站 名单做兼职写小说网站
  • 品牌网站部门建设方案东莞房产网
  • 青岛公司网站建设开发江苏城乡住房建设厅网站