Attachment

Supported by Redmine starting from version 1.3

Manager

All operations on the Attachment resource are provided by its manager. To get access to it you have to call redmine.attachment where redmine is a configured redmine object. See the Configuration about how to configure redmine object.

Create methods

Not supported by Redmine. Some resources support adding attachments via their create/update methods, e.g. Issue, WikiPage.

Read methods

get

redminelib.managers.ResourceManager.get(resource_id)

Returns single Attachment resource from Redmine by its id.

Parameters:

resource_id (int) – (required). Id of the attachment.

Returns:

Resource object

>>> attachment = redmine.attachment.get(76905)
>>> attachment
<redminelib.resources.Attachment #76905 "1(a).png">

Hint

Attachment can be easily downloaded via the provided download() method which is a proxy to the redmine.download() method which provides several options to control the saving process (see docs for details):

>>> attachment = redmine.attachment.get(76905)
>>> filepath = attachment.download(savepath='/usr/local/', filename='image.jpg')
>>> filepath
'/usr/local/image.jpg'

all

Not supported by Redmine

filter

Not supported by Redmine

Update methods

Added in version 2.1.0.

Requires Redmine >= 3.4.0

update

redminelib.managers.ResourceManager.update(resource_id, **fields)

Updates values of given fields of an Attachment resource and saves them to the Redmine.

Parameters:
  • resource_id (int) – (required). Attachment id.

  • filename (string) – (optional). File name.

  • description (string) – (optional). File description.

  • content_type (string) – (optional). File content-type.

Returns:

True

>>> redmine.attachment.update(
...     1,
...     filename='foo.txt',
...     description='foobar',
...     content_type='text/plain'
... )
True

save

redminelib.resources.Attachment.save(**attrs)

Saves the current state of an Attachment resource to the Redmine. Attrs that can be changed are the same as for update() method above.

Returns:

Resource object

>>> attachment = redmine.attachment.get(1)
>>> attachment.filename = 'foo.txt'
>>> attachment.description = 'foobar'
>>> attachment.content_type = 'text/plain'
>>> attachment.save()
<redminelib.resources.Attachment #1 "foo.txt">

Added in version 2.1.0: Alternative syntax was introduced.

>>> attachment = redmine.attachment.get(1).save(
...     filename='foo.txt',
...     description='foobar',
...     content_type='text/plain'
... )
>>> attachment
<redminelib.resources.Attachment #1 "foo.txt">

Delete methods

Added in version 2.0.0.

Requires Redmine >= 3.3.0

delete

redminelib.managers.ResourceManager.delete(resource_id)

Deletes single Attachment resource from Redmine by its id.

Parameters:

resource_id (int) – (required). Attachment id.

Returns:

True

>>> redmine.attachment.delete(76905)
True
redminelib.resources.Attachment.delete()

Deletes current Attachment resource object from Redmine.

Returns:

True

>>> attachment = redmine.attachment.get(76905)
>>> attachment.delete()
True

Export

Export functionality doesn’t make sense for attachments as they can be downloaded