当前位置:网站首页>Alicloud OSS file upload system
Alicloud OSS file upload system
2022-06-12 01:49:00 【Catch wind and shadow】
@Test
public void testUpload() throws FileNotFoundException {
// Endpoint Take hangzhou for example , Other Region Please fill in according to the actual situation .
String endpoint = "oss-cn-shanghai.aliyuncs.com";
// Cloud accounts AccessKey Have all API Access right , It is recommended to follow Alibaba cloud security best practices , Create and use RAM The sub account number is used for API Visit or daily operations , Please log in https://ram.console.aliyun.com establish .
String accessKeyId = "LTAI4G4W1RA4JXz2QhoDwHhi";
String accessKeySecret = "R99lmDOJumF2x43ZBKT259Qpe70Oxw";
// establish OSSClient example .
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
// Upload file stream .
InputStream inputStream = new FileInputStream("C:\\Users\\Administrator\\Pictures\\timg.jpg");
ossClient.putObject("gulimall-images", "time.jpg", inputStream);
// close OSSClient.
ossClient.shutdown();
System.out.println(" Upload successful .");
}
Detailed usage , see : https://help.aliyun.com/knowledge_detail/108650.html
(1) Add dependency
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alicloud-oss</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
(2) establish “AccessKey ID” and “AccessKeySecret”
(3) To configure key,secret and endpoint Related information
access-key: LTAI4G4W1RA4JXz2QhoDwHhi
secret-key: R99lmDOJumF2x43ZBKT259Qpe70Oxw
oss:
endpoint: oss-cn-shanghai.aliyuncs.com
(4) Inject OSSClient And upload and download files

But it's still troublesome to do so , If the future upload tasks are assigned to gulimall-product To complete , Obviously, the coupling is high . It's best to create a new one Module To complete the file upload task .
spring:
cloud:
alicloud:
access-key: LTAI4G4W1RA4JXz2QhoDwHhi
secret-key: R99lmDOJumF2x43ZBKT259Qpe70Oxw
oss:
endpoint: oss-cn-shanghai.aliyuncs.com
@Test
public void openupload() throws FileNotFoundException{
// Upload file stream .
InputStream inputStream = new FileInputStream( "C:\\Users\\liuyang\\Pictures\\cehsi\\ceshi.jpg" );
ossClient.putObject( "gulimall-hellotest1", "ceshi.jpg", inputStream );
// close OSSClient.
ossClient.shutdown();
System.out.println( " Upload successful ." );
}
边栏推荐
- Four schemes for redis to implement message queue
- Linux(CentOS7)安裝MySQL-5.7版本
- 大一下期:学习总结
- [C language] summary of basic knowledge points of pointer
- In 2022, the internal promotion of the "MIHA Tour" golden, silver and silver social recruitment started in April and march! Less overtime, good welfare, 200+ posts for you to choose, come and see!
- How to restore the redis cluster and retain the complete cluster data after changing the node IP
- 2022 blind box applet app has become a new drainage outlet for enterprises
- kali安装empire过程中遇到的各种报错解决方案
- Entity class dto to VO is converted through plug-in
- The establishment and introduction of the announcement module of PHP development blog system
猜你喜欢

决定广告质量的三个主要因素

Design practice of rongyun Im on electron platform

Several visualization methods of point cloud 3D object detection results (second, pointpillars, pointrcnn)

Concepts of programs, processes, and threads

“還是學一門技術更保險!”杭州校區小哥哥轉行軟件測試,喜提10K+雙休!

Linux(CentOS6)安装MySQL5.5版本数据库

Fatal error in launcher: unable to create process using

Dataset how to use dataset gracefully. After reading this article, you can fully understand the dataset in c7n/choerodon/ toothfish UI

How to access the traifik proxy dashboard using the rancher desktop

Quatre schémas de mise en file d'attente des messages pour redis
随机推荐
Various error reporting solutions encountered by Kali during Empire installation
Redis實現消息隊列的4種方案
2022 blind box applet app has become a new drainage outlet for enterprises
华为,这也太强了吧..
Point cloud perception algorithm interview knowledge points (I)
Educational knowledge and ability test questions of primary and secondary school educational endowment examination in the second half of 2019 (middle school) - subjective questions
Leetcode 55 jump game
lua 函数
Chinese Version Vocaloid AI Tuner Feasibility Test
These three sentences make you not confused when you understand that you are an we media. I just do this. The monthly income of video has exceeded 10000 yuan
Modification of system module information of PHP security development 12 blog system
小程序111111
php开发09 文章模块的删除和文章分类编写
LeetCode LCP 07. Deliver information
Quatre schémas de mise en file d'attente des messages pour redis
Annotate your own point cloud dataset with labelcloud open source tool as a tutorial of Kitti annotation format (support PCD and bin point clouds)
Simulated 100 questions and simulated examination for safety management personnel of metal and nonmetal mines (small open pit quarries) in 2022
How to maximize the use of various matching methods—— Google SEM
How much coverage is appropriate for children's serious illness insurance? Which product is the best?
The role of MOV ah, 4CH int 21