Class AttachmentManager


  • public class AttachmentManager
    extends java.lang.Object
    Works 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 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 Issue
        attachmentFile - the file to upload
        contentType - 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:
        RedmineException
        java.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.