• Auto Unzip on Upload

  • We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
We tried to make OpenKM as intuitive as possible, but an advice is always welcome.
Forum rules: Please, before asking something see the documentation wiki or use the search feature of the forum. And remember we don't have a crystal ball or mental readers, so if you post about an issue tell us which OpenKM are you using and also the browser and operating system version. For more info read How to Report Bugs Effectively.
 #28087  by omnicron
 
Is there a way to make OpenKM default feature to unzip .zip files on upload? Users never click that thing!


Thanks

Tim
 #28095  by jllort
 
You're talking about any zip file uploaded, althought users had not clicked in unzip checkbox, automatically application unzip it internally. Is it ? Force always unzip files.
 #28484  by jllort
 
Could be done creating a simply Automation task based on document creation event. Also take a look at FileUploadServlet.java class where are the private methods what are doing it. The method in what you must be interested is importZip, inpire on it for creating your Automation action. Read here http://wiki.openkm.com/index.php/Extend_automation_6.0 and here http://doxygen.openkm.com/openkm/dc/df7 ... ation.html ( from openkm 6.3 can create a jar file and simply copy into /tomcat/plugins
Code: Select all
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;
	}

About Us

OpenKM is part of the management software. A management software is a program that facilitates the accomplishment of administrative tasks. OpenKM is a document management system that allows you to manage business content and workflow in a more efficient way. Document managers guarantee data protection by establishing information security for business content.