当前位置:网站首页>1. use alicloud object OSS (basic)
1. use alicloud object OSS (basic)
2022-06-11 05:18:00 【A programmer who doesn't like to stay up late but often stays u】
1. Log in to your alicloud account and select 【 Object storage OSS】

2. establish Bucket list
When creating, select according to your own needs Bucket Parameters , Fill in and click OK , For testing purposes
Read / write permission I have chosen , Public reading ( Write requires permission , Read does not require permission )

3. Select the newly created Bucket Parameters , Set up RAM

4. Click create user after entering
We chose programmatic access to improve security , Click OK after filling in , Then get the mobile phone verification code ,


After the creation is successful, a pop-up message will appear :AccessKey ID,AccessKey Secret, Copy and save to the text document , Convenient for later use , If you click Close , Need to reacquire ,
Recapture
1)、 Click on the user name 
2)、 Click Create AccessKey ID, Remember to save after generation , because AccessKey Secret There is no place to view , You can only recreate 
5. Set permissions for users 
Click Add permission , Here we only use 【 Manage object storage services (OSS) jurisdiction 】, So we chose it , Then click OK , Then click Finish .( You can configure the entire alicloud account )
6. structure maven project
Import pom rely on
<!-- SpringBoot The core jar package -->
<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>
<!-- Alibaba cloud OSS -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.10.2</version>
</dependency>
</dependencies>
New startup class , newly added controller

@Controller
public class OSSController {
@RequestMapping("/getOSSClient")
public @ResponseBody String getOSSClient() throws FileNotFoundException {
// yourEndpoint Fill in Bucket The region corresponding to Endpoint. East China 1( Hangzhou ) For example ,Endpoint Fill in for https://oss-cn-hangzhou.aliyuncs.com.
String endpoint = "endpoint";
// Alicloud account AccessKey Have all the API Access rights of , The risk is high . It is highly recommended that you create and use it RAM The user carries out API Visit or daily operations , Please log in RAM Console creation RAM user .
String accessKeyId = "accessKeyId";
String accessKeySecret = "accessKeySecret";
// establish OSSClient example .
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// Fill in the full path of the local file . If no local path is specified , By default, the file stream is uploaded from the local path corresponding to the project to which the sample program belongs .
InputStream inputStream = new FileInputStream("D:\\VUE\\001.jpg");
// Fill in... In turn Bucket name ( for example examplebucket) and Object The full path ( for example exampledir/exampleobject.txt).Object The full path cannot contain Bucket name .
ossClient.putObject("Bucket name ", "001.jpg", inputStream);
// close OSSClient.
ossClient.shutdown();
System.out.println("============================");
return " Upload successful ";
}
}
Here we mainly get four parameters :
1.endpoint
2.accessKeyId( The application account number has been obtained )
3.accessKeySecret( The application account number has been obtained )
4.Bucket name
endpoint obtain
1)、 Get into OSS home page 、 Click access path , Click Overview


2)、Bucket name
Get into OSS home page , Click on Bucket list 
7. Start project
visit :http://localhost:8080/getOSSClient
The browser prints and uploads successfully 
Enter Alibaba cloud OSS, file management , You can see what I just uploaded 001.jpg The file 
Because we don't have read permission , So we can directly access the uploaded files , At this point, we click Details , Copy url You can access the image directly .

边栏推荐
- 27、移除元素
- What is a smart network card? What is the function of the smart network card?
- Leetcode 161 Editing distance of 1 (2022.06.10)
- oh my zsh正确安装姿势
- 自定义View基础之Layout
- Lianrui: how to rationally see the independent R & D of domestic CPU and the development of domestic hardware
- Some details about memory
- Share | defend against physically realizable image classification attacks
- Deep search + backtracking
- C (I) C basic grammar all in one
猜你喜欢

Lr-link Lianrui fully understands the server network card
![[NIPS2021]MLP-Mixer: An all-MLP Architecture for Vision](/img/89/66c30ea8d7969fef76785da1627ce5.jpg)
[NIPS2021]MLP-Mixer: An all-MLP Architecture for Vision

Sealem Finance打造Web3去中心化金融平台基础设施

华为设备配置通过GRE隧道接入虚拟专用网

Vins fusion GPS fusion part

Iris dataset - Introduction to machine learning

微信小程序,购买商品属性自动换行,固定div个数,超出部分自动换行

华为设备配置BGP/MPLS IP 虚拟专用网

Yolov5 training personal data set summary

Huawei equipment is configured to access the virtual private network through GRE tunnel
随机推荐
Take stock of the AI black technologies in the Beijing Winter Olympic Games, and Shenzhen Yancheng Technology
Intercept file extension
Click the icon is not sensitive how to adjust?
C (I) C basic grammar all in one
Network security construction in 5g Era
Lr-link Lianrui fully understands the server network card
Tightly coupled laser vision inertial navigation slam system: paper notes_ S2D. 66_ ICRA_ 2021_ LVI-SAM
About custom comparison methods of classes and custom methods of sort functions
Analysis while experiment - a little optimization of memory leakage in kotlin
22、生成括号
GAMES101作业7-Path Tracing实现过程&代码详细解读
Section III: structural characteristics of cement concrete pavement
华为设备配置BGP/MPLS IP 虚拟专用网命令
How to purchase 25g optical network card
35.搜索插入位置
Combien de courant le câblage des PCB peut - il supporter?
Retinanet+keras train their own data set to tread on the pit
Free data | new library online | cnopendata data data of national heritage stores and auction enterprises
Huawei equipment is configured with bgp/mpls IP virtual private network
Analyzing while experimenting - memory leakage caused by non static inner classes