package com.itheima;
import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
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";
// 阿里云账号AccessKey拥有所有API的访问权限,风险很高。强烈建议您创建并使用RAM用户进行API访问或日常运维,请登录RAM控制台创建RAM用户。
String accessKeyId = "LTAI4GCH1vX6DKqJWxd6nEuW";
String accessKeySecret = "yBshYweHOpqDuhCArrVHwIiBKpyqSL";
// 填写Bucket名称,例如examplebucket。
String bucketName = "web-tlias";
// 填写Object完整路径,完整路径中不能包含Bucket名称,例如exampledir/exampleobject.txt。
String objectName = "1.jpg";
// 填写本地文件的完整路径,例如D:\\localpath\\examplefile.txt。
// 如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
String filePath= "C:\\Users\\Administrator\\Pictures\\Camera Roll\\1.jpg";
// 创建OSSClient实例。
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
try {
InputStream inputStream = new FileInputStream(filePath);
// 创建PutObject请求。
ossClient.putObject(bucketName, objectName, inputStream);
} 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();
}
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
spring bootweb案例
共45个文件
class:18个
java:18个
xml:3个
需积分: 0 0 下载量 147 浏览量
2023-06-10
17:35:33
上传
评论
收藏 41KB RAR 举报
温馨提示
spring bootweb案例
资源推荐
资源详情
资源评论
收起资源包目录
tlias-web-management.rar (45个子文件)
tlias-web-management
pom.xml 4KB
src
test
java
com
itheima
TliasWebManagementApplicationTests.java 396B
Demo.java 3KB
main
resources
templates
static
upload.html 438B
application.yml 649B
com
itheima
mapper
EmpMapper.xml 2KB
java
com
itheima
TliasWebManagementApplication.java 340B
mapper
EmpMapper.java 2KB
DeptMapper.java 814B
controller
UploadController.java 2KB
EmpController.java 2KB
DeptController.java 2KB
utils
AliOSSUtils.java 2KB
AliOSSProperties.java 416B
pojo
PageBean.java 344B
Dept.java 435B
Result.java 729B
Emp.java 823B
service
impl
EmpServiceImpl.java 2KB
DeptServiceImpl.java 826B
DeptService.java 420B
EmpService.java 802B
target
classes
static
upload.html 438B
application.yml 649B
META-INF
spring-configuration-metadata.json 788B
com
itheima
TliasWebManagementApplication.class 765B
mapper
EmpMapper.xml 2KB
DeptMapper.class 791B
EmpMapper.class 1KB
controller
DeptController.class 2KB
UploadController.class 2KB
EmpController.class 4KB
utils
AliOSSUtils.class 2KB
AliOSSProperties.class 3KB
pojo
Result.class 3KB
Dept.class 3KB
PageBean.class 2KB
Emp.class 7KB
service
DeptService.class 363B
impl
EmpServiceImpl.class 3KB
DeptServiceImpl.class 1KB
EmpService.class 661B
test-classes
com
itheima
Demo.class 3KB
TliasWebManagementApplicationTests.class 930B
generated-test-sources
test-annotations
generated-sources
annotations
tlias-web-management.iml 12KB
共 45 条
- 1
资源评论
梦~001
- 粉丝: 7
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功