|
@@ -1,10 +1,7 @@
|
|
|
package com.gis.common.util;
|
|
|
|
|
|
import com.aliyun.oss.OSSClient;
|
|
|
-import com.aliyun.oss.model.OSSObject;
|
|
|
-import com.aliyun.oss.model.OSSObjectSummary;
|
|
|
-import com.aliyun.oss.model.ObjectListing;
|
|
|
-import com.aliyun.oss.model.PutObjectResult;
|
|
|
+import com.aliyun.oss.model.*;
|
|
|
import com.gis.common.constant.ConfigConstant;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -56,6 +53,29 @@ public class AliyunOssUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ *
|
|
|
+ * @param data
|
|
|
+ * @param key
|
|
|
+ * @param contentType : 不设置,默认浏览器打开图片
|
|
|
+ * application/octet-stream 使用cdn后会自动下载
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ public void upload(byte[] data, String key, String contentType) throws IOException {
|
|
|
+ OSSClient ossClient = init();
|
|
|
+
|
|
|
+ // 创建上传文件的元信息,可以通过文件元信息设置HTTP header。
|
|
|
+ ObjectMetadata meta = new ObjectMetadata();
|
|
|
+ meta.setContentType(contentType);
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 2019-2-28 启动aliyun oss 空间
|
|
|
+ ossClient.putObject(configConstant.ossBucket, key, new ByteArrayInputStream(data), meta);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.toString() + key);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
public void upload(String filePath, String key) {
|
|
|
OSSClient ossClient = init();
|