|
|
@@ -14,6 +14,7 @@ import p2.util.P2Exception;
|
|
|
import java.io.*;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Base64;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@@ -43,18 +44,23 @@ public class OSSManage extends Controller {
|
|
|
* @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 ownerid = content.getString("ownerid");
|
|
|
String ftype = content.getString("ftype");
|
|
|
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 = "";
|
|
|
if (ftype == null || ftype.equals("")) {
|
|
|
key = filename;
|
|
|
@@ -62,7 +68,7 @@ public class OSSManage extends Controller {
|
|
|
key = ftype + "/" + filename;
|
|
|
}
|
|
|
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();
|
|
|
String url = file_url + "/" + rootpath + key;
|
|
|
|
|
|
@@ -75,11 +81,11 @@ public class OSSManage extends Controller {
|
|
|
paoRemote.setValue("ownerid", ownerid, 11L);
|
|
|
paoRemote.setValue("createby", username, 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("fdocument", file.getName(), 11L);
|
|
|
+ paoRemote.setValue("fdocument", name, 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);
|
|
|
paoSetRemote.save();
|
|
|
|
|
|
@@ -102,18 +108,21 @@ public class OSSManage extends Controller {
|
|
|
if (tattachmentid == null || tattachmentid.equals("")) {
|
|
|
return getErrReturnObject().setErrMsg("附件id为空").toString();
|
|
|
}
|
|
|
- String filePath = content.getString("filePath");
|
|
|
+ String name = content.getString("filename");
|
|
|
String ownertable = content.getString("ownertable");
|
|
|
String ownerid = content.getString("ownerid");
|
|
|
String ftype = content.getString("ftype");
|
|
|
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 = "";
|
|
|
if (ftype == null || ftype.equals("")) {
|
|
|
key = filename;
|
|
|
@@ -121,7 +130,7 @@ public class OSSManage extends Controller {
|
|
|
key = ftype + "/" + filename;
|
|
|
}
|
|
|
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();
|
|
|
String url = file_url + "/" + rootpath + key;
|
|
|
|
|
|
@@ -135,11 +144,11 @@ public class OSSManage extends Controller {
|
|
|
paoRemote.setValue("ownerid", ownerid, 11L);
|
|
|
paoRemote.setValue("createby", username, 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("fdocument", file.getName(), 11L);
|
|
|
+ paoRemote.setValue("fdocument", name, 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);
|
|
|
paoSetRemote.save();
|
|
|
|