Search in sources :

Example 1 with DocumentUploadSession

use of org.kie.workbench.common.forms.jbpm.server.service.impl.documents.DocumentUploadSession in project kie-wb-common by kiegroup.

the class FormsDocumentServlet method doPost.

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Map<String, Object> response = new HashMap<>();
    try {
        FileItem fileItem = getFileItem(req);
        String id = UUID.randomUUID().toString();
        String content = Base64.getEncoder().encodeToString(fileItem.get());
        DocumentUploadChunk chunk = new DocumentUploadChunk(id, fileItem.getName(), 0, 1, content);
        DocumentUploadSession session = new DocumentUploadSession(chunk.getDocumentId(), chunk.getDocumentName(), chunk.getMaxChunks());
        session.add(chunk);
        storage.uploadContentChunk(chunk);
        session.setState(DocumentUploadSession.State.MERGING);
        storage.merge(session);
        DocumentData data = new DocumentData(id, fileItem.getName(), fileItem.getSize(), "", System.currentTimeMillis());
        response.put("document", data);
    } catch (Exception e) {
        response.put("error", "error");
    } finally {
        writeResponse(resp, response);
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) DocumentUploadSession(org.kie.workbench.common.forms.jbpm.server.service.impl.documents.DocumentUploadSession) HashMap(java.util.HashMap) DocumentUploadChunk(org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadChunk) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1 FileItem (org.apache.commons.fileupload.FileItem)1 DocumentData (org.kie.workbench.common.forms.jbpm.model.document.DocumentData)1 DocumentUploadSession (org.kie.workbench.common.forms.jbpm.server.service.impl.documents.DocumentUploadSession)1 DocumentUploadChunk (org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadChunk)1