Add a file attachment
Add a file attachment to a file in your library programmatically.This request requires authentication. To create an attachment, the currently authenticated user must be the owner of the user library containing the document, an administrator, or have been shared with as an editor. To test whether the current user can create a file attachment, use the Retrieve file metadata API with the acls parameter set to true ", and check the <td:permission> element for the AddChild flag. See Authenticating requests for information about how to authenticate the request.
Table 1. Atom API request details
Method Resource address Input representation Description POST /basic/api/myuserlibrary/document/{document-id}/feed media resource entry resource
multipart content
Adds a file attachment to a file in your library.
Note: {document-id} is the value of the <td:uuid> or <td:label> element in the Atom entry document of the file to which you want to add the attachment.You can use one or more of these headers.
Table 2. Input headers
Parameter Required Description Content-Type Yes Used to specify the mime type for the content being sent to the server. If the collection does not support the specified content type, the server returns HTTP response code 415 (Unsupported media type). When a media resource is posted, the mime-type of the resource is set to this value if it is provided. Otherwise, the mime-type of the extension of the Slug header is used. A Content-Type that is an empty string, whitespace only, or equal to "unknown/unknown" is considered to be not-specified. If this header is not present on the request, then the server returns a HTTP response code of 400 (Bad request). Content-Language Yes Specifies the language of the content being sent to the server. All contents are handled using UTF-8 encoding on the server. Content-Length Yes Specifies the content length when sending media content. If this header is not present on the request, then the server returns a HTTP response code of 411 (Length required). Slug Yes Contains the file path and label of the resource to be added to the file. You can include non-ASCII characters in this header, but they must be correctly encoded according to RFC 2047. You can use one or more of these input parameters. Separate multiple parameters with an ampersand (&).
Table 3. Input parameters when providing a media resource
Parameter Description created Date to use as the creation date of the file attachment. Specify the time in the number of milliseconds since 1 January 1970, 00:00:00 GMT. This value can be set by the user, and defaults to the current system time on the server. identifier Indicates how the document is identified in the {document-id} variable segment of the web address. By default, the lookup operation is performed with the expectation that the URL contains the value from the <td:uuid> element of a attachment Atom entry, so the value uuid is used. Specify label if the URL instead contains the value from the <td:label> element of a attachment Atom entry. modified Date to use as the last modified date of the file attachment. Specify the time in the number of milliseconds since January 1, 1970, 00:00:00 GMT time. This value can be set by the user, and defaults to the current system time on the server. Table 4. Input parameters when providing multipart content
Parameter Description created Date to use as the creation date of the file attachment. Specify the time in the number of milliseconds since 1 January 1970, 00:00:00 GMT. This value can be set by the user, and defaults to the current system time on the server. identifier Indicates how the document is identified in the {document-id} variable segment of the web address. By default, the lookup operation is performed with the expectation that the URL contains the value from the <td:uuid> element of a attachment Atom entry, so the value uuid is used. Specify label if the URL instead contains the value from the <td:label> element of a attachment Atom entry. modified Date to use as the last modified date of the file attachment. Specify the time in the number of milliseconds since 1 January 1970, 00:00:00 GMT. This value can be set by the user, and defaults to the current system time on the server. replace Specifies whether to replace an existing attachment, if there is one. Options are true or false. The default value is false.
Input
The following types of file attachments are supported:
- Media resource
- Multipart content
Output
An Atom entry document representing the new file attachment.Returned HTTP headers
HTTP/1.1 201 Created
Indicates that the file attachment was successfully created. If an error occurs, this header contains one of the error codes.
- HTTP/1.1 401 Unauthorized
- HTTP/1.1 403 Forbidden
- HTTP/1.1 404 Not Found
- HTTP/1.1 409 Conflict
- HTTP/1.1 411 Length required
- HTTP/1.1 415 Unsupported media type
Parent topic
Work with file attachments programmaticallyRelated reference
File attachment content
});