Skip to content

Function: createOrUpdateAttachments()

ts
function createOrUpdateAttachments(client, parameters): Promise<ContentArray>;

Defined in: src/v1/api/contentAttachments.ts:94

Adds an attachment to a piece of content. If the attachment already exists for the content, then the attachment is updated (i.e. a new version of the attachment is created).

The media type 'multipart/form-data' is defined in RFC 7578. Most client libraries have classes that make it easier to implement multipart posts, like the MultipartEntityBuilder Java class provided by Apache HTTP Components.

Note, according to RFC 7578, in the case where the form data is text, the charset parameter for the "text/plain" Content-Type may be used to indicate the character encoding used in that part. In the case of this API endpoint, the comment body parameter should be sent with type=text/plain and charset=utf-8 values. This will force the charset to be UTF-8.

Example: This curl command attaches a file ('example.txt') to a piece of content (id='123') with a comment and minorEdits=true. If the 'example.txt' file already exists, it will update it with a new version of the attachment.

bash
curl -D- \
  -u admin:admin \
  -X PUT \
  -H 'X-Atlassian-Token: nocheck' \
  -F 'file=@"example.txt"' \
  -F 'minorEdit="true"' \
  -F 'comment="Example attachment comment"; type=text/plain; charset=utf-8' \
  http://myhost/rest/api/content/123/child/attachment

Permissions required: Permission to update the content.

Parameters

ParameterTypeDescription
clientClient-
parameters{ attachments: | AttachmentInput | AttachmentInput[]; id: string; status?: "current" | "draft"; }-
parameters.attachments| AttachmentInput | AttachmentInput[]-
parameters.idstringThe ID of the content to add the attachment to.
parameters.status?"current" | "draft"The status of the content that the attachment is being added to. This should always be set to 'current'.

Returns

Promise&lt;ContentArray>