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

小米商城网站设计论文网站推广服务费计入什么科目

小米商城网站设计论文,网站推广服务费计入什么科目,扬州工程建设信息 网站,wordpress如何改代码注册阿里云账号后,开通好对象存储服务#xff08;OSS#xff09;#xff0c;三个月试用 阿里云登录页 (aliyun.com) 目录 一.创建Bucket 二.获取AccessKey#xff08;密钥#xff09; 三.参考官方SDK文件#xff0c;编写入门程序 1.复制阿里云OSS依赖#xff0c;粘贴… 注册阿里云账号后,开通好对象存储服务OSS三个月试用     阿里云登录页 (aliyun.com) 目录 一.创建Bucket 二.获取AccessKey密钥 三.参考官方SDK文件编写入门程序 1.复制阿里云OSS依赖粘贴到pom.xml文件里 ​2. 将上传文件流的Demo测试类复制到test文件里 四.集成OSS运用于项目中 1. 在yml文件配置自定义阿里云OSS信息 2.编写阿里云工具类官方代码改编 3.编写文件上传类接口 一.创建Bucket 二.获取AccessKey密钥 注意保存好你的AccessKey ID 三.参考官方SDK文件编写入门程序 1.复制阿里云OSS依赖粘贴到pom.xml文件里 !--阿里云OSS--dependencygroupIdcom.aliyun.oss/groupIdartifactIdaliyun-sdk-oss/artifactIdversion3.15.1/version/dependency 2. 将上传文件流的Demo测试类复制到test文件里 import com.aliyun.oss.ClientException; import com.aliyun.oss.OSS; import com.aliyun.oss.common.auth.*; import com.aliyun.oss.OSSClientBuilder; import com.aliyun.oss.OSSException; import com.aliyun.oss.model.PutObjectRequest; import com.aliyun.oss.model.PutObjectResult; import java.io.FileInputStream; import java.io.InputStream;public class Demo {public static void main(String[] args) throws Exception {// Endpoint以华东1杭州为例其它Region请按实际情况填写。String endpoint https://oss-cn-hangzhou.aliyuncs.com;// 从环境变量中获取访问凭证。运行本代码示例之前请确保已设置环境变量OSS_ACCESS_KEY_ID和OSS_ACCESS_KEY_SECRET。EnvironmentVariableCredentialsProvider credentialsProvider CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();// 填写Bucket名称例如examplebucket。String bucketName examplebucket;// 填写Object完整路径完整路径中不能包含Bucket名称例如exampledir/exampleobject.txt。String objectName exampledir/exampleobject.txt;// 填写本地文件的完整路径例如D:\\localpath\\examplefile.txt。// 如果未指定本地路径则默认从示例程序所属项目对应本地路径中上传文件流。String filePath D:\\localpath\\examplefile.txt;// 创建OSSClient实例。OSS ossClient new OSSClientBuilder().build(endpoint, credentialsProvider);try {InputStream inputStream new FileInputStream(filePath);// 创建PutObjectRequest对象。PutObjectRequest putObjectRequest new PutObjectRequest(bucketName, objectName, inputStream);// 创建PutObject请求。PutObjectResult result ossClient.putObject(putObjectRequest);} 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();}}} } 注意需配置环境变量然后修改为自己的配置 ①添加系统环境变量即你的AccesskKyId和accessKeySecret ②修改Demo里的endpoint、bucketName、objectName和filePath 只需修改这四个用于测试运行Demo查看OSS上传成功 四.集成OSS运用于项目中 1. 在yml文件配置自定义阿里云OSS信息 ①在AliOSSProperties类中先使用ConfigurationProperties自动注入到yml中 import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component;Data Component ConfigurationProperties(prefix aliyun.oss) public class AliOSSProperties {private String endpoint;private String accessKeyId;private String accessKeySecret;private String bucketName; } ②然后在yml文件中配置阿里云OSS 2.编写阿里云工具类官方代码改编 import com.aliyun.oss.OSS; import com.aliyun.oss.OSSClientBuilder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import java.io.*; import java.util.UUID;/*** 阿里云 OSS 工具类*/ Component ConfigurationProperties public class AliOSSUtils {Autowiredprivate AliOSSProperties aliOSSProperties;/*** 实现上传图片到OSS*/public String upload(MultipartFile file) throws IOException {//获取阿里云OSS参数String endpoint aliOSSProperties.getEndpoint();String accessKeyId aliOSSProperties.getAccessKeyId();String accessKeySecret aliOSSProperties.getAccessKeySecret();String bucketName aliOSSProperties.getBucketName();// 获取上传的文件的输入流InputStream inputStream file.getInputStream();// 避免文件覆盖String originalFilename file.getOriginalFilename();String fileName UUID.randomUUID().toString() originalFilename.substring(originalFilename.lastIndexOf(.));//上传文件到 OSSOSS ossClient new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);ossClient.putObject(bucketName, fileName, inputStream);//文件访问路径String url endpoint.split(//)[0] // bucketName . endpoint.split(//)[1] / fileName;// 关闭ossClientossClient.shutdown();return url;// 把上传到oss的路径返回}} 3.编写文件上传类接口 import com.itheima.pojo.Result; import com.itheima.utils.AliOSSUtils; 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.RestController; import org.springframework.web.multipart.MultipartFile;import java.io.IOException;Slf4j RestController public class UploadController {//注入阿里云工具类Autowiredprivate AliOSSUtils aliOSSUtils;PostMapping(/upload)public Result upload(MultipartFile image) throws IOException {log.info(文件上传文件名{}, image.getOriginalFilename());//调用阿里云OSS工具类进行文件上传String url aliOSSUtils.upload(image);log.info(文件上传完成文件访问的url{}, url);return Result.success(url);} } 至此。后端上传文件至阿里云的代码完成
http://www.yingshimen.cn/news/9598/

相关文章:

  • 做cpa广告网站教程国外买东西的网站有哪些
  • c# 网站开发框架网站禁止火车头采集
  • 聊城网站改版解决国外网站很慢
  • 在线设计网站海报网站怎么制作免费的
  • 网站建设 杭州为个人网站做微信服务号
  • 成都网站建设需多少钱网站营销工具
  • 查看WordPress网站插件京东网站建设费用
  • 潍坊寿光网站建设网络加速器有哪些
  • 计算机网站开发图片晋江文创园网站建设
  • 松门建设规划局网站网站和网页的区别在于
  • 上海高品质网站建设公司网站地市频道建设
  • .net网站开发教程百度贴吧平面设计接单软件
  • 官方网站建设的目的教务管理系统密码忘了怎么办
  • 昆山高新区规划建设局网站网站制作公司的网站
  • 北京的制作网站的公司在哪里工程招标建设部指定网站
  • 提供衡水网站建设阿里云做网站经费
  • 国外服务器租用网站页游平台
  • 网站ip段屏蔽网站设计步骤及图解
  • 北京网站设计优选刻电商网站建设方案100例
  • 做彩妆发哪个网站浏览量高本土建站工作室
  • 网站顶部flash南浔城乡建设局网站
  • 深圳市建网站公司群晖 wordpress外网
  • 怎样做展会推广网站wordpress上传视频失败
  • 杭州网站建设费用多少钱邢台网站建设服务周到
  • 网站项目怎么做聚美优品网站怎么做的
  • 贾汪区建设局网站做哪类网站
  • 网站开发答辩记录表装修网站合作平台有哪些
  • 东莞哪家网站建设好网页设计工具一般有哪几种
  • 物流网站制作怎么做互联网公司怎么赚钱
  • 重庆网站推广公司电话百度搜索链接入口