GetDocumentContent
Retrieves the content of an ingested document from a knowledge base, or of an image embedded in the document. Returns a pre-signed URL for downloading the content. Use this operation to display the source of a Retrieve result.
Request Syntax
POST /knowledgebases/knowledgeBaseId/datasources/dataSourceId/documents/documentId/content HTTP/1.1
Content-type: application/json
{
"mediaId": "string",
"outputFormat": "string",
"userContext": {
"userId": "string"
}
}
URI Request Parameters
The request uses the following URI parameters.
- dataSourceId
-
The unique identifier of the data source that contains the document.
Length Constraints: Minimum length of 0. Maximum length of 10.
Pattern:
[0-9a-zA-Z]+Required: Yes
- documentId
-
The unique identifier of the document to retrieve content for.
Length Constraints: Minimum length of 1. Maximum length of 1825.
Pattern:
\P{C}*Required: Yes
- knowledgeBaseId
-
The unique identifier of the knowledge base that contains the document.
Length Constraints: Minimum length of 10. Maximum length of 2048.
Pattern:
[0-9a-zA-Z]{10}$|^arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:[0-9]{12}:knowledge-base/[0-9a-zA-Z]{10}Required: Yes
Request Body
The request accepts the following data in JSON format.
- mediaId
-
The unique identifier (in UUID format) of an image embedded in the specified document. Set this parameter to the
_media_idvalue in the metadata of the correspondingRetrieveresult. If you specify this parameter, the response contains a pre-signed URL for the image instead of the document, and you must omitoutputFormator set it toRAW.Type: String
Length Constraints: Fixed length of 36.
Pattern:
[a-zA-Z0-9][a-zA-Z0-9-]{35}Required: No
- outputFormat
-
The output format for the content. You can specify one of the following values:
- RAW
-
Returns the original document, or the selected image if you specify
mediaId. - EXTRACTED
-
Returns parsed document text as JSON.
If you omit this parameter, the default is
RAW. You can't useEXTRACTEDwithmediaId.Type: String
Valid Values:
RAW | EXTRACTEDRequired: No
- userContext
-
Contains information about the user making the request. This is used for access control filtering to ensure that results only include documents the user is authorized to access.
Type: UserContext object
Required: No
Response Syntax
HTTP/1.1 200
Content-type: application/json
{
"documentContentLength": number,
"mimeType": "string",
"presignedUrl": "string"
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- documentContentLength
-
The size, in bytes, of the content available at the pre-signed URL.
Type: Long
- mimeType
-
The MIME type of the returned content. For
RAWformat, this is the original file type (for example,application/pdf), or the image type (for example,image/png) if you specifymediaId. ForEXTRACTEDformat, this is alwaysapplication/json.Type: String
- presignedUrl
-
A pre-signed URL for downloading the document content, or the selected image if you specify
mediaId. The URL expires after 5 minutes.Type: String
Errors
For information about the errors that are common to all actions, see Common Error Types.
- AccessDeniedException
-
The request is denied because of missing access permissions. Check your permissions and retry your request.
HTTP Status Code: 403
- InternalServerException
-
An internal server error occurred. Retry your request.
- reason
-
The reason for the exception. If the reason is
BEDROCK_MODEL_INVOCATION_SERVICE_UNAVAILABLE, the model invocation service is unavailable. Retry your request.
HTTP Status Code: 500
- ResourceNotFoundException
-
The specified resource Amazon Resource Name (ARN) was not found. Check the Amazon Resource Name (ARN) and try your request again.
HTTP Status Code: 404
- ThrottlingException
-
The number of requests exceeds the limit. Resubmit your request later.
HTTP Status Code: 429
- ValidationException
-
Input validation failed. Check your request parameters and retry the request.
HTTP Status Code: 400
Examples
Retrieve the original document content
The following example retrieves the original (raw) content of a document from a knowledge base. The response includes a pre-signed URL that you can use to download the document.
Sample Request
POST /knowledgebases/KB12345678/datasources/DS12345678/documents/DOC12345678/content HTTP/1.1
Content-type: application/json
{
"outputFormat": "RAW"
}
Retrieve an embedded image
The following example shows the request body for retrieving an image embedded in a document. Specify the knowledge base, data source, and document in the request URI, as in the previous example, using the documentId from a Retrieve result. Set mediaId to the _media_id value from the metadata of the same result.
Sample Request
{
"outputFormat": "RAW",
"mediaId": "a1b2c3d4-5678-90ab-cdef-EXAMPLE11111"
}
Response for an embedded image
The following example response contains a pre-signed URL for the image, the image's MIME type, and its size in bytes. The pre-signed URL is abbreviated.
Sample Response
{
"presignedUrl": "https://amzn-s3-demo-bucket1.s3.us-west-2.amazonaws.com/embedded-image.png?...",
"mimeType": "image/png",
"documentContentLength": 6800
}
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: