ÎļþÃû´Ó ruoyi-oss/src/main/java/com/ruoyi/oss/service/impl/QiniuCloudStorageStrategy.java ÐÞ¸Ä |
| | |
| | | import com.qiniu.storage.UploadManager; |
| | | import com.qiniu.util.Auth; |
| | | import com.ruoyi.oss.entity.UploadResult; |
| | | import com.ruoyi.oss.enumd.CloudServiceEnumd; |
| | | import com.ruoyi.oss.enumd.OssEnumd; |
| | | import com.ruoyi.oss.exception.OssException; |
| | | import com.ruoyi.oss.properties.CloudStorageProperties; |
| | | import com.ruoyi.oss.service.abstractd.AbstractCloudStorageStrategy; |
| | | import com.ruoyi.oss.properties.OssProperties; |
| | | import com.ruoyi.oss.service.abstractd.AbstractOssStrategy; |
| | | |
| | | import java.io.InputStream; |
| | | |
| | |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | public class QiniuCloudStorageStrategy extends AbstractCloudStorageStrategy { |
| | | public class QiniuOssStrategy extends AbstractOssStrategy { |
| | | |
| | | private UploadManager uploadManager; |
| | | private BucketManager bucketManager; |
| | | private String token; |
| | | private Auth auth; |
| | | |
| | | @Override |
| | | public void init(CloudStorageProperties cloudStorageProperties) { |
| | | public void init(OssProperties cloudStorageProperties) { |
| | | properties = cloudStorageProperties; |
| | | try { |
| | | Configuration config = new Configuration(getRegion(properties.getRegion())); |
| | |
| | | config.useHttpsDomains = false; |
| | | config.useHttpsDomains = "Y".equals(properties.getIsHttps()); |
| | | uploadManager = new UploadManager(config); |
| | | Auth auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); |
| | | auth = Auth.create(properties.getAccessKey(), properties.getSecretKey()); |
| | | String bucketName = properties.getBucketName(); |
| | | token = auth.uploadToken(bucketName); |
| | | bucketManager = new BucketManager(auth, config); |
| | | |
| | | if (!ArrayUtil.contains(bucketManager.buckets(), bucketName)) { |
| | |
| | | |
| | | @Override |
| | | public String getServiceType() { |
| | | return CloudServiceEnumd.QINIU.getValue(); |
| | | return OssEnumd.QINIU.getValue(); |
| | | } |
| | | |
| | | @Override |
| | | public UploadResult upload(byte[] data, String path, String contentType) { |
| | | try { |
| | | Response res = uploadManager.put(data, path, token, null, contentType, false); |
| | | String token = auth.uploadToken(properties.getBucketName()); |
| | | Response res = uploadManager.put(data, path, token, null, contentType, false); |
| | | if (!res.isOK()) { |
| | | throw new RuntimeException("ä¸ä¼ ä¸çåºéï¼" + res.toString()); |
| | | throw new RuntimeException("ä¸ä¼ ä¸çåºéï¼" + res.error); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new OssException("ä¸ä¼ æä»¶å¤±è´¥ï¼è¯·æ ¸å¯¹ä¸çé
置信æ¯:[" + e.getMessage() + "]"); |
| | |
| | | path = path.replace(getEndpointLink() + "/", ""); |
| | | Response res = bucketManager.delete(properties.getBucketName(), path); |
| | | if (!res.isOK()) { |
| | | throw new RuntimeException("å é¤ä¸çæä»¶åºéï¼" + res.toString()); |
| | | throw new RuntimeException("å é¤ä¸çæä»¶åºéï¼" + res.error); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new OssException(e.getMessage()); |