com.atlassian.confluence.rest.resources
Class AttachmentResource

java.lang.Object
  extended by com.atlassian.confluence.rest.resources.AttachmentResource

public class AttachmentResource
extends java.lang.Object

CRUD operations for Attachments on Content.


Nested Class Summary
static class AttachmentResource.ConfluenceAttachmentMultipartConfig
           
 
Constructor Summary
AttachmentResource(AttachmentService attachmentService)
           
 
Method Summary
 RestList<Content> createAttachments(ContentId contentId, java.util.List<com.atlassian.plugins.rest.common.multipart.FilePart> fileParts, java.util.List<com.atlassian.plugins.rest.common.multipart.FilePart> comments, java.util.List<com.atlassian.plugins.rest.common.multipart.FilePart> minorEdits)
          Add one or more attachments to a Confluence Content entity, with optional comments.
 RestList<Content> getAttachments(ContentId contentId, java.lang.String expand, int start, int limit, java.lang.String filename, java.lang.String mediaType, javax.ws.rs.core.UriInfo uriInfo)
          Returns a paginated list of attachment Content entities within a single container.
 Content update(java.lang.String attachmentId, Content attachment)
           Update the non-binary data of an Attachment.
 Content updateData(ContentId attachmentId, com.atlassian.plugins.rest.common.multipart.FilePart filePart, com.atlassian.plugins.rest.common.multipart.FilePart comment, com.atlassian.plugins.rest.common.multipart.FilePart minorEdit)
          Update the binary data of an Attachment, and optionally the comment.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AttachmentResource

public AttachmentResource(AttachmentService attachmentService)
Method Detail

getAttachments

@PublicApi
public RestList<Content> getAttachments(ContentId contentId,
                                                  java.lang.String expand,
                                                  int start,
                                                  int limit,
                                                  java.lang.String filename,
                                                  java.lang.String mediaType,
                                                  @Context
                                                  javax.ws.rs.core.UriInfo uriInfo)
                                 throws ServiceException

Returns a paginated list of attachment Content entities within a single container.

Example request URI(s):

  • http://example.com/rest/api/content/1234/attachments?start=0&limit=10
  • http://example.com/rest/api/content/1234/attachments?filename=myfile.txt&expand=version,container

Parameters:
contentId - a string containing the id of the attachments content container
expand - a comma separated list of properties to expand on the Attachments returned. Optional.
start - the index of the first item within the result set that should be returned. Optional.
limit - how many items should be returned after the start index. Optional.
filename - (optional) filter parameter to return only the Attachment with the matching file name. Optional.
mediaType - (optional) filter parameter to return only Attachments with a matching Media-Type. Optional.
uriInfo - (injected) information about the request URI
Returns:
a JSON representation of the content, or a 404 NOT FOUND if there is no content with the given containerId or if the user is not permitted.
Throws:
ServiceException

createAttachments

@PublicApi
public RestList<Content> createAttachments(ContentId contentId,
                                                     java.util.List<com.atlassian.plugins.rest.common.multipart.FilePart> fileParts,
                                                     java.util.List<com.atlassian.plugins.rest.common.multipart.FilePart> comments,
                                                     java.util.List<com.atlassian.plugins.rest.common.multipart.FilePart> minorEdits)
                                    throws ServiceException

Add one or more attachments to a Confluence Content entity, with optional comments.

Comments are optional, but if included there must be as many comments as there are files, and the comments must be in the same order as the files.

This resource expects a multipart post. The media-type multipart/form-data is defined in RFC 1867. Most client libraries have classes that make dealing with multipart posts simple. For instance, in Java the Apache HTTP Components library provides a MultiPartEntity that makes it simple to submit a multipart POST.

In order to protect against XSRF attacks, because this method accepts multipart/form-data, it has XSRF protection on it. This means you must submit a header of X-Atlassian-Token: nocheck with the request, otherwise it will be blocked.

The name of the multipart/form-data parameter that contains attachments must be "file"

A simple example to attach a file called "myfile.txt" to the container with id "123", with a comment included:

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt;comment=This is my File" http://myhost/rest/api/1/content/123/attachments

A example to attach a file called "myfile.txt" to the container with id "123", with a comment, and set the minorEdits flag to be true:

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt;minorEdit=true;comment=This is my File" http://myhost/rest/api/1/content/123/attachments

An example to upload the same file, with no comment:

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" http://myhost/rest/api/1/content/123/attachments/456/data

Example request URI(s):

  • http://example.com/rest/api/content/1234/attachments

Parameters:
contentId - a string containing the id of the attachments content container
fileParts - a list of fileparts containing the data for each attachment to be created
comments - (optional) a list of comments matching the list of attachment data. If supplied, the size of this list must match the size of the fileParts list
minorEdits - (optional) form parameter indicating whether the attachments should be minorEdits. If minorEdits is set to true, no notification email or activity stream will be generated for that attachment.
Returns:
a JSON representation of the attachments added.
Throws:
ServiceException

update

@PublicApi
public Content update(java.lang.String attachmentId,
                                Content attachment)
               throws ServiceException

Update the non-binary data of an Attachment.

This resource can be used to update an attachment's filename, media-type, comment, and parent container.

Example request URI(s):

  • http://example.com/rest/api/content/1234/attachments/5678

Parameters:
attachmentId - the id of the attachment to update
attachment - the details of the Attachment to be updated
Returns:
a JSON representation of the attachment after being updated.
Throws:
ServiceException

updateData

@PublicApi
public Content updateData(ContentId attachmentId,
                                    com.atlassian.plugins.rest.common.multipart.FilePart filePart,
                                    com.atlassian.plugins.rest.common.multipart.FilePart comment,
                                    com.atlassian.plugins.rest.common.multipart.FilePart minorEdit)
                   throws ServiceException

Update the binary data of an Attachment, and optionally the comment.

Comments are optional, but if included there must be as many comments as there are files, and the comments must be in the same order as the files.

This resource expects a multipart post. The media-type multipart/form-data is defined in RFC 1867. Most client libraries have classes that make dealing with multipart posts simple. For instance, in Java the Apache HTTP Components library provides a MultiPartEntity that makes it simple to submit a multipart POST.

In order to protect against XSRF attacks, because this method accepts multipart/form-data, it has XSRF protection on it. This means you must submit a header of X-Atlassian-Token: nocheck with the request, otherwise it will be blocked.

The name of the multipart/form-data parameter that contains attachments must be "file"

A simple example to upload a file called "myfile.txt" to the Attachment with id "456" in a container with id "123", with the comment updated, and minorEdit set to true:

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt;minorEdit=true;comment=This is my updated File" http://myhost/rest/api/1/content/123/attachments/456/data

An example to upload the same file, with no comment:

curl -D- -u admin:admin -X POST -H "X-Atlassian-Token: nocheck" -F "file=@myfile.txt" http://myhost/rest/api/1/content/123/attachments/456/data

Example request URI(s):

  • http://example.com/rest/api/content/1234/attachments/5678/data

Parameters:
attachmentId - the id of the attachment to upload a new file for
filePart - the file to be uploaded
minorEdit - (optional) form parameter indicating whether the attachment should be a minorEdit. If minorEdit is set to true, no notification email or activity stream will be generated for that attachment.
comment - the comment to associate with the attachment - may be a blank string
Returns:
a JSON representation of the attachments added.
Throws:
ServiceException


Copyright © 2003-2014 Atlassian. All Rights Reserved.