当前位置:网站首页>1.使用阿里云对象OSS(初级)
1.使用阿里云对象OSS(初级)
2022-06-11 05:08:00 【一位不爱熬夜但又经常熬夜的程序员】
1.登陆阿里云账号选择【对象存储OSS】

2.创建Bucket列表
创建时根据自身需求选择Bucket参数,填写完成点击确定,为了方便测试
读写权限我选择了,公共读(写需要权限,读取不需要权限)

3.选中刚刚新建的Bucket参数,设置RAM

4.进入后点击创建用户
我们选择编程访问来提高安全性,填写完成后点击确定,然后获取手机验证码,


创建成功后会弹出:AccessKey ID,AccessKey Secret,此时复制保存到文本文档,方便后期使用,如果点击关闭,需要重新获取,
重新获取
1)、点击用户名称
2)、点击创建AccessKey ID,生成后记得保存,因为AccessKey Secret没有地方可以查看,只能重新创建
5.为用户设置权限
点击新增权限,这里我们只用到了【管理对象存储服务(OSS)权限】,所以我们选择它,然后点击确定,然后点击完成。(整个阿里云账号配置就可以了)
6.构建maven项目
导入pom依赖
<!-- SpringBoot核心jar包 -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 阿里云OSS -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
</dependency>
</dependencies>
新增启动类,新增controller

@Controller
public class OSSController {
@RequestMapping("/getOSSClient")
public @ResponseBody String getOSSClient() throws FileNotFoundException {
// yourEndpoint填写Bucket所在地域对应的Endpoint。以华东1(杭州)为例,Endpoint填写为https://oss-cn-hangzhou.aliyuncs.com。
String endpoint = "endpoint";
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
String accessKeyId = "accessKeyId";
String accessKeySecret = "accessKeySecret";
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
InputStream inputStream = new FileInputStream("D:\\VUE\\001.jpg");
// 依次填写Bucket名称(例如examplebucket)和Object完整路径(例如exampledir/exampleobject.txt)。Object完整路径中不能包含Bucket名称。
ossClient.putObject("Bucket名称", "001.jpg", inputStream);
// 关闭OSSClient。
ossClient.shutdown();
System.out.println("============================");
return "上传成功";
}
}
这里主要获取四个参数:
1.endpoint
2.accessKeyId(申请账号已获得)
3.accessKeySecret(申请账号已获得)
4.Bucket名称
endpoint获取
1)、进入OSS首页、点击访问路径,点击概况


2)、Bucket名称
进入OSS首页,点击Bucket 列表
7.启动项目
访问:http://localhost:8080/getOSSClient
浏览器打印上传成功
进入阿里云OSS,文件管理,就可以看到刚刚我上传的001.jpg文件了
由于我们没有设置读权限,所以上传的文件我们可以直接访问,此时我们点击详情,复制url就能直接访问到该图片了。

边栏推荐
- Course design summary
- Google drive download failed, network error
- Yolov5 training personal data set summary
- Cartographer learning record: cartographer Map 3D visualization configuration (self recording dataset version)
- JVM tuning 6: GC log analysis and constant pool explanation
- Detailed explanation of network security bypass network card
- Network security construction in 5g Era
- New product pre-sale: 25g optical network card based on Intel 800 series is coming
- Top 100 video information of station B
- Feynman learning method
猜你喜欢

Conversion relationship between coordinate systems (ECEF, LLA, ENU)

Zed2 camera manual

Zed2 running vins-mono preliminary test

Topological sorting

Huawei equipment is configured with bgp/mpls IP virtual private network

2021 iccv paper sharing - occlusion boundary detection

华为设备配置本地虚拟专用网互访

Share 𞓜 jointly pre training transformers on unpaired images and text

免费数据 | 新库上线 | CnOpenData全国文物商店及拍卖企业数据

Sealem Finance打造Web3去中心化金融平台基础设施
随机推荐
Paper reproduction: pare
Parametric contractual learning: comparative learning in long tail problems
BP neural network derivation + Example
Preliminary understanding of DFS and BFS
Share | defend against physically realizable image classification attacks
Pytoch machine learning GPU usage (conversion from CPU to GPU)
Codesys get System Time
oh my zsh正确安装姿势
Cartographer learning record: cartographer Map 3D visualization configuration (self recording dataset version)
Titanic rescued - re exploration of data mining (ideas + source code + results)
About custom comparison methods of classes and custom methods of sort functions
[Transformer]MViTv1:Multiscale Vision Transformers
Yolact paper reading and analysis
免费数据 | 新库上线 | CnOpenData全国文物商店及拍卖企业数据
Zed2 camera manual
code
What is a smart network card? What is the function of the smart network card?
PCB走线到底能承载多大电流
Reverse thinking: making cartoon photos real
[markdown syntax advanced] make your blog more exciting (III: common icon templates)