Package com.taskadapter.redmineapi
Class AttachmentManager
- java.lang.Object
-
- com.taskadapter.redmineapi.AttachmentManager
-
public class AttachmentManager extends java.lang.ObjectWorks with Attachments (files).Obtain it via RedmineManager:
RedmineManager redmineManager = RedmineManagerFactory.createWithUserAuth(redmineURI, login, password); AttachmentManager attachmentManager = redmineManager.getAttachmentManager();Sample usage:
File file = ... attachmentManager.addAttachmentToIssue(issueId, file, ContentType.TEXT_PLAIN.getMimeType());
- See Also:
RedmineManager.getAttachmentManager()
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AttachmentaddAttachmentToIssue(java.lang.Integer issueId, java.io.File attachmentFile, java.lang.String contentType)voiddelete(int attachmentId)see http://www.redmine.org/issues/14828byte[]downloadAttachmentContent(Attachment issueAttachment)Downloads the content of anAttachmentfrom the Redmine server.voiddownloadAttachmentContent(Attachment issueAttachment, java.io.OutputStream stream)AttachmentgetAttachmentById(int attachmentID)Delivers anAttachmentby its ID.AttachmentuploadAttachment(java.lang.String contentType, java.io.File content)Uploads an attachment.AttachmentuploadAttachment(java.lang.String fileName, java.lang.String contentType, byte[] content)Uploads an attachment.AttachmentuploadAttachment(java.lang.String fileName, java.lang.String contentType, java.io.InputStream content)Uploads an attachment.AttachmentuploadAttachment(java.lang.String fileName, java.lang.String contentType, java.io.InputStream content, long contentLength)Uploads an attachment passing total length.
-
-
-
Method Detail
-
addAttachmentToIssue
public Attachment addAttachmentToIssue(java.lang.Integer issueId, java.io.File attachmentFile, java.lang.String contentType) throws RedmineException, java.io.IOException
- Parameters:
issueId- database ID of the IssueattachmentFile- the file to uploadcontentType- MIME type. depending on this parameter, the file will be recognized by the server as text or image or binary. see http://en.wikipedia.org/wiki/Internet_media_type for possible MIME types. sample value: ContentType.TEXT_PLAIN.getMimeType()- Returns:
- the created attachment object.
- Throws:
RedmineExceptionjava.io.IOException
-
uploadAttachment
public Attachment uploadAttachment(java.lang.String fileName, java.lang.String contentType, byte[] content) throws RedmineException, java.io.IOException
Uploads an attachment.- Parameters:
fileName- file name of the attachment.contentType- content type of the attachment.content- attachment content stream.- Returns:
- attachment content.
- Throws:
RedmineException- if something goes wrong.java.io.IOException- if input cannot be read.
-
uploadAttachment
public Attachment uploadAttachment(java.lang.String contentType, java.io.File content) throws RedmineException, java.io.IOException
Uploads an attachment.- Parameters:
contentType- content type of the attachment.content- attachment content stream.- Returns:
- attachment content.
- Throws:
RedmineException- if something goes wrong.java.io.IOException- if input cannot be read.
-
uploadAttachment
public Attachment uploadAttachment(java.lang.String fileName, java.lang.String contentType, java.io.InputStream content) throws RedmineException, java.io.IOException
Uploads an attachment.- Parameters:
fileName- file name of the attachment.contentType- content type of the attachment.content- attachment content stream.- Returns:
- attachment content.
- Throws:
RedmineException- if something goes wrong.java.io.IOException- if input cannot be read. This exception cannot be thrown yet (I am not sure if http client can distinguish "network" errors and local errors) but is will be good to distinguish reading errors and transport errors.
-
uploadAttachment
public Attachment uploadAttachment(java.lang.String fileName, java.lang.String contentType, java.io.InputStream content, long contentLength) throws RedmineException, java.io.IOException
Uploads an attachment passing total length.- Parameters:
fileName- file name of the attachment.contentType- content type of the attachment.content- attachment content stream.contentLength- attachment length. Use -1 to enable Transfer-encoding: chunked. Pass exact length to avoid that as some web servers (like lighthttpd do not support it)- Returns:
- attachment content.
- Throws:
RedmineException- if something goes wrong.java.io.IOException- if input cannot be read. This exception cannot be thrown yet (I am not sure if http client can distinguish "network" errors and local errors) but is will be good to distinguish reading errors and transport errors.
-
getAttachmentById
public Attachment getAttachmentById(int attachmentID) throws RedmineException
Delivers anAttachmentby its ID.- Parameters:
attachmentID- the ID- Returns:
- the
Attachment - Throws:
RedmineAuthenticationException- thrown in case something went wrong while trying to loginRedmineException- thrown in case something went wrong in RedmineNotFoundException- thrown in case an object can not be found
-
downloadAttachmentContent
public void downloadAttachmentContent(Attachment issueAttachment, java.io.OutputStream stream) throws RedmineException
- Throws:
RedmineException
-
downloadAttachmentContent
public byte[] downloadAttachmentContent(Attachment issueAttachment) throws RedmineException
Downloads the content of anAttachmentfrom the Redmine server.- Parameters:
issueAttachment- theAttachment- Returns:
- the content of the attachment as a byte[] array
- Throws:
RedmineCommunicationException- thrown in case the download failsRedmineException
-
delete
public void delete(int attachmentId) throws RedmineExceptionsee http://www.redmine.org/issues/14828- Throws:
RedmineException- Since:
- Redmine 3.3.0
-
-