对象存储OSS,是阿里提供的一种云存储服务。相较于其他存储方式,OSS更加安全可靠,且成本较低。OSS可以存储任意类型的文件,并且可以在任何地点、时间、和应用上下载和上传文件。
为了使用阿里提供的OSS存储服务,我们需要注册并购买相关产品,低配的OSS很便宜,包年只要九元钱,在购买后,我们需要进入控制台,生成一个AccessKey,用来访问自己的OSS并上传或下载文件。
生成AccessKey后,我们就可以使用OSS了,首先,我们需要在项目中引入相关依赖:
<dependency>
<groupId>com.aliyun.openservices</groupId>
<artifactId>aliyun-openservices</artifactId>
<version>1.2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jdom/jdom -->
<dependency>
<groupId>org.jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson