public AttachmentMeta createAttachmentWithoutQuotaCheck(byte[] content, String filename) { AttachmentContainer container = attachmentManager.createAttachmentContainer(); try { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(container.getContainer().getAbsoluteFile()+"/"+filename))); bos.write(content); bos.close(); } catch (IOException ex) { logger.error("Unable to write exception.log", ex); } AttachmentMeta attachment = container.getMeta(); attachment.setName(filename); return attachment; }
@POST @Path("/grid/file") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public FileVersionId registerFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) throws FileManagerException { if (uploadedInputStream == null || fileDetail == null) throw new RuntimeException("Invalid arguments"); GridClient grid = controller.getContext().get(GridClient.class); AttachmentContainer container = controller.getContext().getAttachmentManager().createAttachmentContainer(); File file = new File(container.getContainer()+"/"+fileDetail.getFileName()); try { Files.copy(uploadedInputStream, file.toPath()); } catch (IOException e) { throw new RuntimeException("Error while saving file."); } FileVersion fileVersion = grid.registerFile(file); return fileVersion.getVersionId(); } }
@POST @Secured @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public UploadResponse uploadFile(@FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) { if (uploadedInputStream == null || fileDetail == null) throw new RuntimeException("Invalid arguments"); AttachmentContainer container = attachmentManager.createAttachmentContainer(); String uploadedFileLocation = container.getContainer() + "/" + fileDetail.getFileName(); try { Files.copy(uploadedInputStream, Paths.get(uploadedFileLocation)); } catch (IOException e) { logger.error("Error while saving file "+uploadedFileLocation, e); throw new RuntimeException("Error while saving file."); } UploadResponse response = new UploadResponse(); response.setAttachmentId(container.getMeta().getId().toString()); return response; }
@POST @Path("/context/{id}/file") @Consumes(MediaType.MULTIPART_FORM_DATA) @Produces(MediaType.APPLICATION_JSON) public String uploadFile(@PathParam("id") String id, @FormDataParam("file") InputStream uploadedInputStream, @FormDataParam("file") FormDataContentDisposition fileDetail) { StagingContext context = stagingContextAccessor.get(id); if (uploadedInputStream == null || fileDetail == null) throw new RuntimeException("Invalid arguments"); AttachmentContainer container = controller.getContext().getAttachmentManager().createAttachmentContainer(); File file = new File(container.getContainer()+"/"+fileDetail.getFileName()); try { Files.copy(uploadedInputStream, file.toPath()); } catch (IOException e) { throw new RuntimeException("Error while saving file."); } context.addAttachment(container.getMeta().getId().toString()); stagingContextAccessor.save(context); return container.getMeta().getId().toString(); }
public ExportStatus createExportTask(String exportId, ExportRunnable runnable) { ExportStatus status = new ExportStatus(exportId); exportStatusMap.put(exportId, status); AttachmentContainer container = attachmentManager.createAttachmentContainer(); status.setAttachmentID(container.getMeta().getId().toString()); runnable.setStatus(status); runnable.setContainer(container.getContainer()); exportExecutor.submit(new Runnable() { @Override public void run() { try { runnable.runExport(); } catch(Exception e) { } finally { status.ready = true; } } }); return status; }