Auto Unzip on Upload
PostPosted:Wed Mar 12, 2014 11:35 pm
Is there a way to make OpenKM default feature to unzip .zip files on upload? Users never click that thing!
Thanks
Tim
Thanks
Tim
Because information matters
https://forum.openkm.com/
private synchronized String importZip(String path, InputStream is) throws PathNotFoundException, ItemExistsException,
AccessDeniedException, RepositoryException, IOException, DatabaseException, ExtensionException, AutomationException {
log.debug("importZip({}, {})", path, is);
java.io.File tmpIn = null;
java.io.File tmpOut = null;
String errorMsg = null;
try {
// Create temporal
tmpIn = File.createTempFile("okm", ".zip");
tmpOut = FileUtils.createTempDir();
FileOutputStream fos = new FileOutputStream(tmpIn);
IOUtils.copy(is, fos);
fos.close();
// Unzip files
File fileTmpIn = new File(tmpIn);
fileTmpIn.archiveCopyAllTo(tmpOut);
File.umount();
// Import files
StringWriter out = new StringWriter();
ImpExpStats stats = RepositoryImporter.importDocuments(null, tmpOut, path, false, false, false, out, new TextInfoDecorator(
tmpOut));
if (!stats.isOk()) {
errorMsg = out.toString();
}
out.close();
} catch (IOException e) {
log.error("Error importing zip", e);
throw e;
} finally {
IOUtils.closeQuietly(is);
if (tmpIn != null) {
org.apache.commons.io.FileUtils.deleteQuietly(tmpIn);
}
if (tmpOut != null) {
org.apache.commons.io.FileUtils.deleteQuietly(tmpOut);
}
}
log.debug("importZip: {}", errorMsg);
return errorMsg;
}