Browse Source

优化图片上传

赵冬冬 4 years ago
parent
commit
21b75b4422

+ 5 - 4
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/controller/UploadCompanyInfoAndProductController.java

@@ -157,6 +157,7 @@ public class UploadCompanyInfoAndProductController {
     @Autowired
     private UmsCompanyFileMapper umsCompanyFileMapper;
 
+    //供应商
     public void addCompanyImg(ForestPath forestPath, String companyName, Long companyId) {
         String path = forestPath.getPath();
         List<String> file = getFile(path);
@@ -177,7 +178,7 @@ public class UploadCompanyInfoAndProductController {
             } catch (Exception e) {
                 throw new RuntimeException("获取文件后缀出错!=======>" + split);
             }
-            imgName = imgName + "." + split[1];
+            imgName = imgName + "." + split[split.length-1];
             String filePath = path + "\\" + str;
             infoFile.setFileUrl(url + imgName);
             if (str.contains("公众号二维码")) {
@@ -284,7 +285,7 @@ public class UploadCompanyInfoAndProductController {
             } catch (Exception e) {
                 throw new RuntimeException("获取文件后缀出错!=======>" + split);
             }
-            String fileName = br + s + "." + split[1];
+            String fileName = br + s + "." + split[split.length-1];
             uploadFileUtil.uploadLocalFile(path + "\\" + oldFileName, fileName);
             if (i > 0) {
                 bu.append("," + url + fileName);
@@ -368,7 +369,7 @@ public class UploadCompanyInfoAndProductController {
 
     }
 
-
+    //首图
     public void updateFile(String path, Long along, String str) {
         String upPath = path + "\\" + str;
         String br = "0/2/" + along + "/";
@@ -385,7 +386,7 @@ public class UploadCompanyInfoAndProductController {
                 } catch (Exception e) {
                     throw new RuntimeException("获取文件后缀出错!=======>" + split);
                 }
-                fs = fs + "." + split[1];
+                fs = fs + "." + split[split.length-1];
                 uploadFileUtil.uploadLocalFile(upPath + "\\" + s, fs);
                 if (s.contains("首图")) {
                     p.setPic(url + fs);

+ 1 - 5
forest-admin/admin-server/src/main/java/com/hwrj/cloud/admin/util/UploadFileUtil.java

@@ -17,10 +17,7 @@ import org.springframework.stereotype.Component;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
 import java.io.IOException;
-
-import static org.bouncycastle.asn1.cmc.CMCStatus.success;
 @Slf4j
 @Component
 public class UploadFileUtil {
@@ -44,7 +41,7 @@ public class UploadFileUtil {
         }catch (Exception e){
             throw new GlobalException("获取文件后缀出错!=======>"+split);
         }
-        path = path+"."+split[1];
+        path = path+"."+split[split.length-1];
         //构建一个带指定对象的配置类
         Configuration cof = new Configuration(Zone.autoZone());
         UploadManager uploadManager = new UploadManager(cof);
@@ -84,7 +81,6 @@ public class UploadFileUtil {
 
     public String uploadLocalFile(String path,String url){
         Configuration cof = new Configuration(Zone.autoZone());
-        String s = path;
         UploadManager uploadManager = new UploadManager(cof);
         try {
             Response response = uploadManager.put(path, url, getUploadToken());