|
|
@@ -1,6 +1,7 @@
|
|
|
package com.zhichen.modules.txcos.service.impl;
|
|
|
|
|
|
import cn.hutool.core.lang.Validator;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.qcloud.cos.COSClient;
|
|
|
import com.qcloud.cos.ClientConfig;
|
|
|
import com.qcloud.cos.auth.BasicCOSCredentials;
|
|
|
@@ -52,11 +53,23 @@ public class CosServiceImpl implements CosService {
|
|
|
String bucketName = TENGXUN_COS_BUCKET_NAME;
|
|
|
String key =fileName; // 对象键,即上传到COS后的文件路径
|
|
|
ObjectMetadata metadata = new ObjectMetadata();
|
|
|
- metadata.setContentType("image/jpeg"); // 设置 Content-Type
|
|
|
+ if (ObjectUtils.isNotNull(file.getImageStatus()) && file.getImageStatus() == 6){
|
|
|
+ metadata.setContentDisposition("attachment; filename=\"" + fileName + "\"");
|
|
|
+
|
|
|
+ // 3. 可选但推荐:设置 MIME 类型为通用二进制流
|
|
|
+ // 这样浏览器更不会尝试预览
|
|
|
+ metadata.setContentType("application/octet-stream");
|
|
|
+
|
|
|
+ // 4. 可选:设置其他元数据
|
|
|
+ // metadata.setContentEncoding("UTF-8");
|
|
|
+ }else {
|
|
|
+ metadata.setContentType("image/jpeg"); // 设置 Content-Type
|
|
|
+ }
|
|
|
// 上传文件
|
|
|
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, inputStream,metadata);
|
|
|
cosClient.putObject(putObjectRequest);
|
|
|
|
|
|
+
|
|
|
// 关闭客户端
|
|
|
cosClient.shutdown();
|
|
|
return key;
|