第一步,创建一个maven工程让,然后导包
<!-- aliyun.oss_SDK依赖包 -->
<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>2.5.0</version>
</dependency>
然后你就可以写代码了,那么我们就来做个文件上传的案例
package 。。。。。。。
import java.io.File;
import com.aliyun.oss.OSSClient;
/**
* 文件上传至阿里云
* API https://help.aliyun.com/document_detail/31884.html?spm=5176.doc31883.2.3.K0te63
* @author Administrator
*/
public class FileUpLoad {
public static void upLoad(){
// endpoint,region请按实际情况填写
String endpoint = "http://oss-cn-hangzhou.aliyuncs.com";
// accessKey登录https://ak-console.aliyun.com/查看
String accessKeyId = "<AccessKeyId>";
String accessKeySecret = "<AccessKeySecret>";
// 创建OSSClient实例
OSSClient ossClient = new OSSClient(endpoint, accessKeyId, accessKeySecret);
// 上传文件
ossClient.putObject("bucketName", "key", new File("E:/images/1.jpg"));
//关闭client
ossClient.shutdown();
}
public static void main(String[] args) {
FileUpLoad.upLoad();
}
}
然后在阿里云注册个帐号并且开通oss服务,然后就可以测试了
其他功能官网上去查,就不多写了