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

如何进行网站宣传推广wordpress列表插件

如何进行网站宣传推广,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.hkea.cn/news/14283538/

相关文章:

  • 深圳建站服务中心大型网络建站公司
  • 网站建设如何添加歌曲怎样免费建立自己的网站
  • 北京网站制作开发公司番禺网站建设公司
  • 做兼职的网站策划书WordPress抓去微信
  • 网站建设怎么让百度搜索到跨境电商公司招聘岗位及要求
  • 买个购物网站网站怎么管理维护
  • 微网站模板建设的选择宁波市高等级公路建设指挥部网站
  • 网站开发哪个公司好金融企业如何做好网络推广
  • 电子商务网站建设精英博客登录注册
  • 网站顶部网络宣传渠道有哪些
  • 联合会网站建设wordpress 重制密码
  • 地方门户网站设计100种广告设计
  • 做视频网站的方法云南做网站多少钱
  • 营销型网站建设的优势有哪些怎么看公司网站是哪里做的
  • 毕业设计网站论文海口网站建设的开发方案
  • 如何做百度秒收录网站百度开户返点
  • h5个网站的区别成都如何寻找做网站的
  • h5企业网站源码请勿直接解析到ip否则我司不能保证您的网站能正常运行!"
  • 品牌宣传型网站有哪些房管局
  • 大连网站网页设计公司佛山市做网站的
  • 网站外链建设常用字网站建设改代码改哪些
  • 建设自己的网站需要哪些步骤两学一做材料上哪个网站找
  • 公司网站如何做二维码广州市专业网站设计
  • 邢台营销型网站制作重庆网站建设营销
  • python 网站开发 普及wordpress添加过滤器
  • 正规网站建设推荐宁波网站建设优化排名
  • 卖环保设备做哪个网站好如何网页优化
  • 个人摄影作品网站烟台网站开发制作
  • 网站seo优化心得麻豆人文化活动策划有限公司
  • 南宁网站设计seo优化流程