public virtual AttachmentDto getAttachment(string attachmentId) { ensureHistoryEnabled(Status.NOT_FOUND); Attachment attachment = engine.TaskService.getTaskAttachment(taskId, attachmentId); if (attachment == null) { throw new InvalidRequestException(Status.NOT_FOUND, "Task attachment with id " + attachmentId + " does not exist for task id '" + taskId + "'."); } return(AttachmentDto.fromAttachment(attachment)); }
public virtual AttachmentDto addAttachment(UriInfo uriInfo, MultipartFormData payload) { ensureHistoryEnabled(Status.FORBIDDEN); ensureTaskExists(Status.BAD_REQUEST); MultipartFormData.FormPart attachmentNamePart = payload.getNamedPart("attachment-name"); MultipartFormData.FormPart attachmentTypePart = payload.getNamedPart("attachment-type"); MultipartFormData.FormPart attachmentDescriptionPart = payload.getNamedPart("attachment-description"); MultipartFormData.FormPart contentPart = payload.getNamedPart("content"); MultipartFormData.FormPart urlPart = payload.getNamedPart("url"); if (urlPart == null && contentPart == null) { throw new InvalidRequestException(Status.BAD_REQUEST, "No content or url to remote content exists to create the task attachment."); } string attachmentName = null; string attachmentDescription = null; string attachmentType = null; if (attachmentNamePart != null) { attachmentName = attachmentNamePart.TextContent; } if (attachmentDescriptionPart != null) { attachmentDescription = attachmentDescriptionPart.TextContent; } if (attachmentTypePart != null) { attachmentType = attachmentTypePart.TextContent; } Attachment attachment = null; try { if (contentPart != null) { MemoryStream byteArrayInputStream = new MemoryStream(contentPart.BinaryContent); attachment = engine.TaskService.createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, byteArrayInputStream); } else if (urlPart != null) { attachment = engine.TaskService.createAttachment(attachmentType, taskId, null, attachmentName, attachmentDescription, urlPart.TextContent); } } catch (ProcessEngineException e) { throw new InvalidRequestException(Status.BAD_REQUEST, e, "Task id is null"); } URI uri = uriInfo.BaseUriBuilder.path(rootResourcePath).path(org.camunda.bpm.engine.rest.TaskRestService_Fields.PATH).path(taskId + "/attachment/" + attachment.Id).build(); AttachmentDto attachmentDto = AttachmentDto.fromAttachment(attachment); // GET / attachmentDto.addReflexiveLink(uri, HttpMethod.GET, "self"); return(attachmentDto); }