springboot快速接入七牛云返回token

首先引入依赖:


    com.qiniu
    happy-dns-java
    0.1.4
    compile


    com.qiniu
    qiniu-java-sdk
    [7.2.0, 7.2.99]

接下来是配置 

qiniu:
  accessKey: (个人中心的accessKey)
  secretKey: (个人中心的secretKey)
  url: (空间默认的url)
  bucket: 空间名
  expires: 72000

 java类:

package com.cy.framework.model.qiniu;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(
        prefix = "service.qiniu"
)
public class QinNiuParam {
    private String accessKey;
    private String secretKey;
    /**
     * 请求的url
     */
    private String url;
    /**
     * 空间名称
     */
    private String bucket;
    /**
     * token 存在的时间 单位/秒
     */
    private int expires;

    public int getExpires() {
        return expires;
    }

    public void setExpires(int expires) {
        this.expires = expires;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public String getBucket() {
        return bucket;
    }

    public void setBucket(String bucket) {
        this.bucket = bucket;
    }

}
Auth auth = Auth.create(qinNiuParam.getAccessKey(), qinNiuParam.getSecretKey()); 
String upToken = auth.uploadToken(qinNiuParam.getBucket(),null, qinNiuParam.getExpires(), null);

 返回upToken给前台进行上传

你可能感兴趣的:(上传,七牛云,springboot)