Skip to content

Commit 171dffb

Browse files
committed
store file
1 parent 32a7d9a commit 171dffb

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

framework/src/main/java/com/angkorteam/pluggable/framework/RepositoryUtils.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
import com.angkorteam.pluggable.framework.service.ResourceController;
1414
import com.angkorteam.pluggable.framework.wicket.RestController;
1515

16-
//import com.angkorteam.pluggable.framework.framework.service.ResourceController;
17-
1816
public final class RepositoryUtils {
1917

2018
private RepositoryUtils() {
@@ -55,11 +53,43 @@ private static String localStore(AbstractWebApplication application,
5553
return FrameworkConstants.REPOSITORY_LOCAL_URI + filename;
5654
}
5755

56+
private static String localStore(AbstractWebApplication application,
57+
File file) {
58+
String system = String.valueOf(System.nanoTime());
59+
String clientName = file.getName();
60+
String exentsion = FilenameUtils.getExtension(clientName);
61+
String filename = null;
62+
if (exentsion == null || "".equals(exentsion)) {
63+
filename = org.apache.commons.codec.digest.DigestUtils
64+
.md5Hex(system);
65+
} else {
66+
filename = org.apache.commons.codec.digest.DigestUtils
67+
.md5Hex(system) + "." + exentsion;
68+
}
69+
70+
String local = application.select(FrameworkConstants.REPOSITORY,
71+
String.class);
72+
File copyTo = new File(local, filename);
73+
74+
try {
75+
FileUtils.copyFile(file, copyTo);
76+
FileUtils.deleteQuietly(file);
77+
} catch (IOException e) {
78+
FileUtils.deleteQuietly(copyTo);
79+
return null;
80+
}
81+
return FrameworkConstants.REPOSITORY_LOCAL_URI + filename;
82+
}
83+
5884
public static String store(AbstractWebApplication application,
5985
FileUpload fileUpload) {
6086
return localStore(application, fileUpload);
6187
}
6288

89+
public static String store(AbstractWebApplication application, File file) {
90+
return localStore(application, file);
91+
}
92+
6393
private static void localDelete(AbstractWebApplication application,
6494
String filename) {
6595
String local = application.select(FrameworkConstants.REPOSITORY,

0 commit comments

Comments
 (0)