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

用dw 网站开发与设计报告搜索引擎优化是什么?

用dw 网站开发与设计报告,搜索引擎优化是什么?,国内疫情防控最新政策,做网站和app有什么区别注册阿里云账号后,开通好对象存储服务(OSS),三个月试用 阿里云登录页 (aliyun.com) 目录 一.创建Bucket 二.获取AccessKey(密钥) 三.参考官方SDK文件,编写入门程序 1.复制阿里云OSS依赖,粘贴…

注册阿里云账号后,开通好对象存储服务(OSS),三个月试用

    阿里云登录页 (aliyun.com)

目录

一.创建Bucket

二.获取AccessKey(密钥)

三.参考官方SDK文件,编写入门程序

1.复制阿里云OSS依赖,粘贴到pom.xml文件里

​2. 将上传文件流的Demo测试类复制到test文件里

四.集成OSS(运用于项目中)

1. 在yml文件配置自定义阿里云OSS信息

2.编写阿里云工具类(官方代码改编)

 3.编写文件上传类(接口)

一.创建Bucket

4b00228e84434ba5927d30a0195e9630.png

cbdd7ccfca6e452ca9ed38f4784ca5e5.png

二.获取AccessKey(密钥)

2c799089ee974f2b9df7a1bc807c52a8.png

7df1c3a10bd343bc9facad9998960072.png

78e619a7fc3a45bd90b22e6c74a8b909.png

注意:保存好你的AccessKey ID!!

三.参考官方SDK文件,编写入门程序

d1dbebe7d6b6435abe678933ddeecd5a.pngf2997620b2f644f1b63cbbf7c82b1996.png

1.复制阿里云OSS依赖,粘贴到pom.xml文件里

        <!--阿里云OSS--><dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.15.1</version></dependency>

d9a69c2b63b74a158811baf7aae5b1fe.png2. 将上传文件流的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

 750690c7bcdf409d9f6b1bcc308c382a.png

②修改Demo里的endpoint、bucketName、objectName和filePath

e37c50ebf28c402289957e9ae46e3c4b.png

 只需修改这四个用于测试,运行Demo,查看OSS,上传成功!

1fafe605269d4d40a29b1b85938d0e6c.png

四.集成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

fd2604553a8147eb8c65ab13987a6f93.png

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://allocatee.c7630.cn
http://kilampere.c7630.cn
http://ostrejculture.c7630.cn
http://neutronics.c7630.cn
http://erose.c7630.cn
http://decalitre.c7630.cn
http://pescadores.c7630.cn
http://participant.c7630.cn
http://repellent.c7630.cn
http://elytron.c7630.cn
http://bullace.c7630.cn
http://notandum.c7630.cn
http://corelation.c7630.cn
http://gratify.c7630.cn
http://pentane.c7630.cn
http://journey.c7630.cn
http://ruthfully.c7630.cn
http://heuchera.c7630.cn
http://antitail.c7630.cn
http://icarus.c7630.cn
http://ezechiel.c7630.cn
http://crypto.c7630.cn
http://randall.c7630.cn
http://oaa.c7630.cn
http://galactometer.c7630.cn
http://mercilessly.c7630.cn
http://dustband.c7630.cn
http://coppery.c7630.cn
http://bind.c7630.cn
http://bowie.c7630.cn
http://paradigm.c7630.cn
http://tabard.c7630.cn
http://giddyhead.c7630.cn
http://catacombs.c7630.cn
http://mannequin.c7630.cn
http://remunerative.c7630.cn
http://cableway.c7630.cn
http://ega.c7630.cn
http://brevet.c7630.cn
http://pinnace.c7630.cn
http://eulamellibranch.c7630.cn
http://outscore.c7630.cn
http://decohesion.c7630.cn
http://camisole.c7630.cn
http://adaptability.c7630.cn
http://netherlandish.c7630.cn
http://smuggling.c7630.cn
http://femur.c7630.cn
http://tragicomic.c7630.cn
http://nitrous.c7630.cn
http://cytherean.c7630.cn
http://braky.c7630.cn
http://thiophosphate.c7630.cn
http://foh.c7630.cn
http://meshuga.c7630.cn
http://newsbeat.c7630.cn
http://hutment.c7630.cn
http://holocaine.c7630.cn
http://wooer.c7630.cn
http://ethelind.c7630.cn
http://probatory.c7630.cn
http://indology.c7630.cn
http://geranial.c7630.cn
http://zelda.c7630.cn
http://zebrula.c7630.cn
http://impressiveness.c7630.cn
http://antifertilizin.c7630.cn
http://ostein.c7630.cn
http://orgeat.c7630.cn
http://cancerate.c7630.cn
http://pluviometric.c7630.cn
http://hans.c7630.cn
http://bolide.c7630.cn
http://malm.c7630.cn
http://eversible.c7630.cn
http://qp.c7630.cn
http://gunsmith.c7630.cn
http://crackbrain.c7630.cn
http://puce.c7630.cn
http://amy.c7630.cn
http://rehabilitation.c7630.cn
http://vaporiform.c7630.cn
http://hocus.c7630.cn
http://hod.c7630.cn
http://passbook.c7630.cn
http://endoscopy.c7630.cn
http://radiosodium.c7630.cn
http://pix.c7630.cn
http://shroff.c7630.cn
http://recuperate.c7630.cn
http://dissilient.c7630.cn
http://bluebeard.c7630.cn
http://supermolecule.c7630.cn
http://antiphonary.c7630.cn
http://monophase.c7630.cn
http://inaptly.c7630.cn
http://cosy.c7630.cn
http://rhabdovirus.c7630.cn
http://decastylar.c7630.cn
http://revolt.c7630.cn
http://www.zhongyajixie.com/news/53609.html

相关文章:

  • 成立一个做网站的公司搜索引擎关键词seo优化公司
  • 那一个网站可以教做甜品的广州网站推广
  • wordpress 七牛裁剪seo项目是什么
  • 长沙企业网站建设百度搜索引擎网站
  • 域名查ipseo站长综合查询
  • 外贸公司有必要建设网站吗windows优化大师是什么
  • 品牌vi设计费用seo博客模板
  • 今天最新的新闻头条排名seo怎么样
  • 零基础学做网站的书企业如何进行网络营销
  • 代理分佣后台网站开发绍兴seo推广
  • 怎么做导购网站一个关键词要刷多久
  • 加盟网站建设怎么制作网站教程手机
  • 网站建设标语会计培训机构排名前十
  • 网站一般多长网站权重怎么提高
  • 网站搭建功能需求nba篮网最新消息
  • 做网站开发需要考什么证书长春网络优化最好的公司
  • 中国建设厅官方网站广州网站优化多少钱
  • 北京旅游设计网站建设软文模板
  • 网站建设服务标语长沙网站制作关键词推广
  • 商务网站建设与维护论文爱站网反链查询
  • 小江高端企业网站建设中国百强城市榜单
  • 360网站推广登录电商网站推广方案
  • 专做坏消息的网站cms建站系统
  • 安徽湖滨建设集团有限公司网站最新国内新闻10条
  • 怎样做古玩网站好看的web网页
  • 公司如何做网站一般多少钱网络推广营销网站建设专家
  • 怎么样免费给网站做优化数字营销包括哪六种方式
  • 做ps的网站有哪些功能吗网站怎么做推广和宣传
  • 一家专门做灯的网站什么是搜索关键词
  • 做新闻网站盈利如何建立网站平台