فهرست منبع

附件上传类型调整

吴志根 4 سال پیش
والد
کامیت
1f5707686c

+ 17 - 13
src/dsb/com/cnd3b/restcontroller/enterprise/datacenter/datacenter.java

@@ -13,6 +13,7 @@ import java.io.File;
 import java.io.UnsupportedEncodingException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.net.URLDecoder;
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Base64;
 import java.util.List;
 import java.util.List;
 
 
 import static com.cnd3b.utility.aliyun.oss.AliyunOSSConfigConstant.BUCKE_NAME_1;
 import static com.cnd3b.utility.aliyun.oss.AliyunOSSConfigConstant.BUCKE_NAME_1;
@@ -98,23 +99,26 @@ public class datacenter extends Controller {
      * @return
      * @return
      */
      */
     public String uploadFile() {
     public String uploadFile() {
-        String filePath = content.getString("filePath");
+//        String filePath = content.getString("filePath");
         String folderPath = content.getString("folderPath");
         String folderPath = content.getString("folderPath");
-        if (filePath.equals("") || filePath == null) {
-            return getErrReturnObject().setErrMsg("文件路径不能为空").toString();
-        }
-        if (folderPath.equals("") || folderPath == null) {
-            folderPath = "";
-        }
-        File file = new File(filePath);
-        if (!file.exists()) {
-            return getErrReturnObject().setErrMsg("文件不存在").toString();
-        }
+        String name = content.getString("filename");
+        String base64Str = content.getString("byteStr");
+        byte[] byteStr = Base64.getDecoder().decode(base64Str);
+//        if (filePath.equals("") || filePath == null) {
+//            return getErrReturnObject().setErrMsg("文件路径不能为空").toString();
+//        }
+//        if (folderPath.equals("") || folderPath == null) {
+//            folderPath = "";
+//        }
+//        File file = new File(filePath);
+//        if (!file.exists()) {
+//            return getErrReturnObject().setErrMsg("文件不存在").toString();
+//        }
 
 
-        String key = folderPath + file.getName();
+        String key = folderPath + name;
         System.err.println(key);
         System.err.println(key);
 
 
-        ossClient.putObject(new PutObjectRequest(BUCKE_NAME_1, rootpath + key, file));
+        ossClient.putObject(new PutObjectRequest(BUCKE_NAME_1, rootpath + key, new ByteArrayInputStream(byteStr)));
         ossClient.shutdown();
         ossClient.shutdown();
         return getSucReturnObject().toString();
         return getSucReturnObject().toString();
     }
     }

+ 30 - 21
src/dsb/com/cnd3b/restcontroller/system/system/OSSManage.java

@@ -14,6 +14,7 @@ import p2.util.P2Exception;
 import java.io.*;
 import java.io.*;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.ArrayList;
+import java.util.Base64;
 import java.util.Date;
 import java.util.Date;
 import java.util.List;
 import java.util.List;
 
 
@@ -43,18 +44,23 @@ public class OSSManage extends Controller {
      * @throws P2Exception
      * @throws P2Exception
      */
      */
     public String uploadAttachment() throws P2Exception {
     public String uploadAttachment() throws P2Exception {
-        String filePath = content.getString("filePath");
+//        String filePath = content.getString("filePath");
+        String name = content.getString("filename");
         String ownertable = content.getString("ownertable");
         String ownertable = content.getString("ownertable");
         String ownerid = content.getString("ownerid");
         String ownerid = content.getString("ownerid");
         String ftype = content.getString("ftype");
         String ftype = content.getString("ftype");
         String ftitle = content.getString("ftitle");
         String ftitle = content.getString("ftitle");
+        String postfix = content.getString("postfix");
+        String base64Str = content.getString("byteStr");
+        byte[] byteStr = Base64.getDecoder().decode(base64Str);
 
 
-        File file = new File(filePath);
-        if (!file.exists()) {
-            return getErrReturnObject().setErrMsg("文件不存在").toString();
-        }
+
+//        File file = new File(filePath);
+//        if (!file.exists()) {
+//            return getErrReturnObject().setErrMsg("文件不存在").toString();
+//        }
         //上传文件到阿里云
         //上传文件到阿里云
-        String filename = Getnum() + "-" + file.getName();
+        String filename = Getnum() + "-" + name;
         String key = "";
         String key = "";
         if (ftype == null || ftype.equals("")) {
         if (ftype == null || ftype.equals("")) {
             key = filename;
             key = filename;
@@ -62,7 +68,7 @@ public class OSSManage extends Controller {
             key = ftype + "/" + filename;
             key = ftype + "/" + filename;
         }
         }
         OSS ossClient = new OSSClientBuilder().build(END_POINT, AccessKey_ID, AccessKey_Secret);
         OSS ossClient = new OSSClientBuilder().build(END_POINT, AccessKey_ID, AccessKey_Secret);
-        ossClient.putObject(new PutObjectRequest(BUCKE_NAME_1, rootpath + key, file));
+        ossClient.putObject(new PutObjectRequest(BUCKE_NAME_1, rootpath + key, new ByteArrayInputStream(byteStr)));
         ossClient.shutdown();
         ossClient.shutdown();
         String url = file_url + "/" + rootpath + key;
         String url = file_url + "/" + rootpath + key;
 
 
@@ -75,11 +81,11 @@ public class OSSManage extends Controller {
         paoRemote.setValue("ownerid", ownerid, 11L);
         paoRemote.setValue("ownerid", ownerid, 11L);
         paoRemote.setValue("createby", username, 11L);
         paoRemote.setValue("createby", username, 11L);
         paoRemote.setValue("ftype", ftype, 11L);
         paoRemote.setValue("ftype", ftype, 11L);
-        paoRemote.setValue("postfix", FileTypeHelper.getFileByFile(file), 11L);
+        paoRemote.setValue("postfix", postfix, 11L);
         paoRemote.setValue("serialnumber", filename, 11L);
         paoRemote.setValue("serialnumber", filename, 11L);
-        paoRemote.setValue("fdocument", file.getName(), 11L);
+        paoRemote.setValue("fdocument", name, 11L);
         paoRemote.setValue("fobsurl", url, 11L);
         paoRemote.setValue("fobsurl", url, 11L);
-        paoRemote.setValue("contentlength", String.valueOf(file.length()), 11L);
+        paoRemote.setValue("contentlength", String.valueOf(byteStr.length), 11L);
         paoRemote.setValue("ftitle", ftitle, 11L);
         paoRemote.setValue("ftitle", ftitle, 11L);
         paoSetRemote.save();
         paoSetRemote.save();
 
 
@@ -102,18 +108,21 @@ public class OSSManage extends Controller {
         if (tattachmentid == null || tattachmentid.equals("")) {
         if (tattachmentid == null || tattachmentid.equals("")) {
             return getErrReturnObject().setErrMsg("附件id为空").toString();
             return getErrReturnObject().setErrMsg("附件id为空").toString();
         }
         }
-        String filePath = content.getString("filePath");
+        String name = content.getString("filename");
         String ownertable = content.getString("ownertable");
         String ownertable = content.getString("ownertable");
         String ownerid = content.getString("ownerid");
         String ownerid = content.getString("ownerid");
         String ftype = content.getString("ftype");
         String ftype = content.getString("ftype");
         String ftitle = content.getString("ftitle");
         String ftitle = content.getString("ftitle");
-
-        File file = new File(filePath);
-        if (!file.exists()) {
-            return getErrReturnObject().setErrMsg("文件不存在").toString();
-        }
+        String postfix = content.getString("postfix");
+        String base64Str = content.getString("byteStr");
+        byte[] byteStr = Base64.getDecoder().decode(base64Str);
+
+//        File file = new File(filePath);
+//        if (!file.exists()) {
+//            return getErrReturnObject().setErrMsg("文件不存在").toString();
+//        }
         //上传文件到阿里云
         //上传文件到阿里云
-        String filename = Getnum() + "-" + file.getName();
+        String filename = Getnum() + "-" + name;
         String key = "";
         String key = "";
         if (ftype == null || ftype.equals("")) {
         if (ftype == null || ftype.equals("")) {
             key = filename;
             key = filename;
@@ -121,7 +130,7 @@ public class OSSManage extends Controller {
             key = ftype + "/" + filename;
             key = ftype + "/" + filename;
         }
         }
         OSS ossClient = new OSSClientBuilder().build(END_POINT, AccessKey_ID, AliyunOSSConfigConstant.AccessKey_Secret);
         OSS ossClient = new OSSClientBuilder().build(END_POINT, AccessKey_ID, AliyunOSSConfigConstant.AccessKey_Secret);
-        ossClient.putObject(new PutObjectRequest(BUCKE_NAME_1, rootpath + key, file));
+        ossClient.putObject(new PutObjectRequest(BUCKE_NAME_1, rootpath + key, new ByteArrayInputStream(byteStr)));
         ossClient.shutdown();
         ossClient.shutdown();
         String url = file_url + "/" + rootpath + key;
         String url = file_url + "/" + rootpath + key;
 
 
@@ -135,11 +144,11 @@ public class OSSManage extends Controller {
             paoRemote.setValue("ownerid", ownerid, 11L);
             paoRemote.setValue("ownerid", ownerid, 11L);
             paoRemote.setValue("createby", username, 11L);
             paoRemote.setValue("createby", username, 11L);
             paoRemote.setValue("ftype", ftype, 11L);
             paoRemote.setValue("ftype", ftype, 11L);
-            paoRemote.setValue("postfix", FileTypeHelper.getFileByFile(file), 11L);
+            paoRemote.setValue("postfix", postfix, 11L);
             paoRemote.setValue("serialnumber", filename, 11L);
             paoRemote.setValue("serialnumber", filename, 11L);
-            paoRemote.setValue("fdocument", file.getName(), 11L);
+            paoRemote.setValue("fdocument", name, 11L);
             paoRemote.setValue("fobsurl", url, 11L);
             paoRemote.setValue("fobsurl", url, 11L);
-            paoRemote.setValue("contentlength", String.valueOf(file.length()), 11L);
+            paoRemote.setValue("contentlength", String.valueOf(byteStr.length), 11L);
             paoRemote.setValue("ftitle", ftitle, 11L);
             paoRemote.setValue("ftitle", ftitle, 11L);
             paoSetRemote.save();
             paoSetRemote.save();