|
@@ -15,6 +15,7 @@ import java.util.UUID;
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
|
+import com.zskk.dicom.config.OSSConfig;
|
|
|
import com.zskk.dicom.monitor.config.Configs;
|
|
|
import com.zskk.dicom.monitor.report.ErrReporter;
|
|
|
import com.zskk.dicom.monitor.utils.ExceptionUtil;
|
|
@@ -26,12 +27,22 @@ public class FileUploader {
|
|
|
private static ExecutorService pools = Executors.newFixedThreadPool(2);;
|
|
|
|
|
|
public static void upload(File file) {
|
|
|
+ if(file == null || !file.exists()) {
|
|
|
+ ErrReporter.report("file 为空 或者 file不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
try {
|
|
|
String boundaryKey = UUID.randomUUID().toString().replaceAll("-", "").substring(8, 24);
|
|
|
String content = "\r\n----" + boundaryKey + "\r\n" + "Content-Type: application/octet-stream\r\n" + "Content-Disposition: form-data; name=\"" + renameFileName(file.getName()) + "\"; filename=\"" + renameFileName(file.getName()) + "\"\r\n" + "Content-Transfer-Encoding: binary\r\n\r\n";
|
|
|
String postUrl = "http://" + Configs.postHost + ":" + Configs.postPort + Configs.postUri;
|
|
|
// Boolean uploadResult = uploadToUrl(postUrl, boundaryKey, content, "", file);
|
|
|
- Boolean uploadResult = OSSFileAndCallbackHleper.getInstance().upload(file);
|
|
|
+ Boolean uploadResult = false;
|
|
|
+ try {
|
|
|
+ uploadResult = new OSSFileAndCallbackHleper(Configs.ossEndpoint, OSSConfig.ACCESS_KEY_ID, OSSConfig.ACCESS_KEY_SECRET).upload(file);
|
|
|
+ } catch (Exception e) {
|
|
|
+ ErrReporter.report(ExceptionUtil.getExceptionTxt(e));
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
if (uploadResult == true) {
|
|
|
// 创建目录
|
|
|
String targetFileStr = MonitorFileUtils.touchBackDir(file);
|