当前位置:网站首页>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就能直接访问到该图片了。

边栏推荐
- Lr-link Lianrui fully understands the server network card
- Differences between the four MQ
- Huawei equipment is configured to access the virtual private network through GRE tunnel
- Learning summary 01- machine learning
- Simple linear regression of sklearn series
- KD-Tree and LSH
- Huawei equipment is configured with cross domain virtual private network
- Yolov5 training personal data set summary
- 高斯白噪声(white Gaussian noise,WGN)
- Cascade EF gan: local focus progressive facial expression editing
猜你喜欢

Share | defend against physically realizable image classification attacks

Tightly coupled laser vision inertial navigation slam system: paper notes_ S2D. 66_ ICRA_ 2021_ LVI-SAM

English digital converter

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

Zed2 camera manual

Zed2 camera calibration -- binocular, IMU, joint calibration

【入门级基础】Node基础知识总结

点击图标不灵敏咋整?

Yolov5 training personal data set summary

KD-Tree and LSH
随机推荐
BP neural network derivation + Example
2021 iccv paper sharing - occlusion boundary detection
[markdown syntax advanced] make your blog more exciting (III: common icon templates)
6 questions to ask when selecting a digital asset custodian
Simple linear regression of sklearn series
PCB走线到底能承载多大电流
Apply the intelligent OCR identification technology of Shenzhen Yanchang technology to break through the bottleneck of medical bill identification at one stroke. Efficient claim settlement is not a dr
华为设备配置通过GRE隧道接入虚拟专用网
Retinanet+keras train their own data set to tread on the pit
Take stock of the AI black technologies in the Beijing Winter Olympic Games, and Shenzhen Yancheng Technology
Oh my Zsh correct installation posture
Pytoch machine learning GPU usage (conversion from CPU to GPU)
Cross modal retrieval | visual representation learning
New product release: Lianrui launched a dual port 10 Gigabit bypass network card
[Transformer]MViTv2:Improved Multiscale Vision Transformers for Classification and Detection
Some details about memory
Yolact paper reading and analysis
Emnlp2021 𞓜 a small number of data relation extraction papers of deepblueai team were hired
Learning summary 01- machine learning
The solution "no hardware is configured for this address and cannot be modified" appears during botu simulation