API Get Comment File

From IVS Wiki
Jump to: navigation, search

This API call retrieves a specific file attached to a comment as a direct binary download. The response body contains the raw file bytes. The Content-Disposition: attachment response header instructs the client to download the file, and the Content-Type header will reflect the type of the file (e.g. application/pdf, image/png).

Resource URL

http://valt.example.com/api/v3/comment/{commentId}/files/{fileId}

Replace {commentId} with the ID of the comment and {fileId} with the ID of the file.

Resource Information

Method GET
Headers Content-Type: application/json
Response Type Binary File Download
Authentication Required Yes

Parameters

Path Parameters

Parameter Description Example
commentId The ID of the comment that owns the file. 42
fileId The ID of the file to retrieve. 20

Response

Code Reason
200 File Retrieved Successfully
400 Invalid Request (See Response for Specific Error)
401 Unauthorized
404 Comment or File Not Found
500 Internal Server Error

A successful response returns the binary contents of the file as a direct download. Notable response headers include:

Header Description
Content-Type The MIME type of the file (e.g. application/pdf, image/png).
Content-Disposition Set to attachment; filename="...", instructing the client to download the file.
Content-Length The size of the file in bytes.

The file IDs associated with a comment can be obtained from the files array returned by the API View Comment or API View All Comments by Recording endpoints. Each file entry in that array contains the id, name, and size (in bytes) of the attachment.

Examples

Request

https://ivstest1.ad.ipivs.com/api/v3/comment/42/files/20?access_token=e82632d19c523678fea3d1016c6df9e9

cURL Examples

When making this request via the command line with cURL, the raw binary will be dumped to the terminal by default. Use one of the following approaches to save the file instead.

Save with a manually specified filename:

curl -o myfile.pdf "https://ivstest1.ad.ipivs.com/api/v3/comment/42/files/20?access_token=e82632d19c523678fea3d1016c6df9e9"

Save using the filename provided by the server in the Content-Disposition header:

curl -J -O "https://ivstest1.ad.ipivs.com/api/v3/comment/42/files/20?access_token=e82632d19c523678fea3d1016c6df9e9"

The -J flag instructs cURL to use the filename from the Content-Disposition header, and -O writes the response to a file rather than stdout.

Not Found Response

Returned when no comment or file exists with the specified IDs.

{
  "title": "An error occurred",
  "status": 404,
  "detail": "Not Found"
}

Failure Response

Sample response is shown with line breaks to make it more readable. Actual responses will not include line breaks.

{
  "error": {
    "code": 500,
    "message": "Internal Server Error"
  }
}