Cloudinary

properties

1
2
3
com.cloudinary.cloud_name=<your_cloud_name>
com.cloudinary.api_key=<your_api_key>
com.cloudinary.api_secret=<your_api_secret>

pom.xml

1
2
3
4
5
6
7
8
9
10
<dependency>
<groupId>com.cloudinary</groupId>
<artifactId>cloudinary-http44</artifactId>
<version>${cloudinary.version}</version>
</dependency>
<dependency>
<groupId>com.cloudinary</groupId>
<artifactId>cloudinary-taglib</artifactId>
<version>${cloudinary.version}</version>
</dependency>

Java

生成签名,提供给客户端自行上传

1
2
3
4
5
6
7
8
val params = HashMap<String, Any>()
params["public_id"] = signature.publicId
params["folder"] = signature.folder
params["resourcetype"] = signature.resourceType
params["type"] = signature.type
params["tags"] = signature.tags
params["access_mode"] = signature.access_mode
val sign = cloudinary.apiSignRequest(params, cloudinaryProperties.apiSecret)

授权临时访问URL

1
2
3
4
5
6
val option = HashMap<String, Any>()
option["expires_at"] = TimeUtil.getUnixTime(10 * 6000)
option["cloud_name"] = cloudinaryProperties.cloudName
option["api_key"] = cloudinaryProperties.apiKey
option["api_secret"] = cloudinaryProperties.apiSecret
cloudinary.privateDownload(publicId, "jpg", option)