|
|
@ -4,7 +4,9 @@ import com.aliyun.oss.OSSClient; |
|
|
|
import com.fr.cache.Attachment; |
|
|
|
import com.fr.cache.Attachment; |
|
|
|
import com.fr.general.FArray; |
|
|
|
import com.fr.general.FArray; |
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
import com.fr.general.GeneralUtils; |
|
|
|
|
|
|
|
import com.fr.locale.InterProviderFactory; |
|
|
|
import com.fr.script.Calculator; |
|
|
|
import com.fr.script.Calculator; |
|
|
|
|
|
|
|
import com.fr.stable.ArrayUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import com.fr.stable.xml.FRFile; |
|
|
|
import com.fr.stable.xml.FRFile; |
|
|
|
|
|
|
|
|
|
|
@ -16,7 +18,8 @@ public class OssUpload { |
|
|
|
OssSubmitTarget[] submitTargets = submitTargetConfig.getSubmitTargets(); |
|
|
|
OssSubmitTarget[] submitTargets = submitTargetConfig.getSubmitTargets(); |
|
|
|
for (OssSubmitTarget target : submitTargets) { |
|
|
|
for (OssSubmitTarget target : submitTargets) { |
|
|
|
OssVariableValue fileObject = target.getFile(); |
|
|
|
OssVariableValue fileObject = target.getFile(); |
|
|
|
Object file = calculator.evalValue(GeneralUtils.objectToString(fileObject)); |
|
|
|
String filePath = GeneralUtils.objectToString(fileObject); |
|
|
|
|
|
|
|
Object file = calculator.evalValue(filePath); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uploadFile(ossClient, target.getBucket(), file, |
|
|
|
uploadFile(ossClient, target.getBucket(), file, |
|
|
@ -27,7 +30,7 @@ public class OssUpload { |
|
|
|
|
|
|
|
|
|
|
|
private static void uploadFile( OSSClient ossClient, String bucket, Object file, String directory, String newFileName) { |
|
|
|
private static void uploadFile( OSSClient ossClient, String bucket, Object file, String directory, String newFileName) { |
|
|
|
if (file instanceof FRFile) { |
|
|
|
if (file instanceof FRFile) { |
|
|
|
ossClient.putObject(bucket, directory + "/" + combineName(((FRFile) file).getFileName(), newFileName), new ByteArrayInputStream(((FRFile) file).getBytes())); |
|
|
|
uploadSingleFile(ossClient, bucket, directory, combineName(((FRFile) file).getFileName(), newFileName), ((FRFile) file).getBytes()); |
|
|
|
} else if (file instanceof FArray && ((FArray) file).length() != 0) { |
|
|
|
} else if (file instanceof FArray && ((FArray) file).length() != 0) { |
|
|
|
FArray array = (FArray)file; |
|
|
|
FArray array = (FArray)file; |
|
|
|
for (int i = 0; i < array.length(); i++) { |
|
|
|
for (int i = 0; i < array.length(); i++) { |
|
|
@ -37,12 +40,19 @@ public class OssUpload { |
|
|
|
uploadFile(ossClient, bucket, element, directory, newFileName); |
|
|
|
uploadFile(ossClient, bucket, element, directory, newFileName); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ossClient.putObject(bucket, directory + "/" + combineName(((Attachment) element).getFilename(), newFileName), new ByteArrayInputStream(((Attachment) element).getBytes())); |
|
|
|
uploadSingleFile(ossClient, bucket, directory, combineName(((Attachment) element).getFilename(), newFileName), ((Attachment) element).getBytes()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static void uploadSingleFile(OSSClient ossClient, String bucket, String directory, String newFileName, byte[] bytes) { |
|
|
|
|
|
|
|
if (ArrayUtils.isEmpty(bytes)) { |
|
|
|
|
|
|
|
throw new RuntimeException(InterProviderFactory.getProvider().getLocText("Plugin-File_Submit_Oss_Failed", newFileName)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ossClient.putObject(bucket, directory + "/" + newFileName, new ByteArrayInputStream(bytes)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
/* |
|
|
|
* 这里的逻辑是: |
|
|
|
* 这里的逻辑是: |
|
|
|
* 1、如果没有设置文件名,就用上传的文件的名字; |
|
|
|
* 1、如果没有设置文件名,就用上传的文件的名字; |
|
|
|