Get Preview
The Get Preview
command allows you to retrieve the preview metadata associated with an object stored in your DID Space. This metadata, often in YAML format, defines how an object might be rendered or displayed as a preview.
For a general overview of preview operations, refer to the Preview Commands section.
Parameters#
To retrieve preview metadata, you need to provide the following parameter:
Name | Type | Description |
---|---|---|
|
| The path to the folder containing the object for which you want to retrieve preview metadata. This path must end with a forward slash ( |
Returns#
The Get Preview
command returns an object with the following properties upon successful execution:
Name | Type | Description |
---|---|---|
|
| The HTTP status code of the response. A value of |
|
| The HTTP status message corresponding to the status code. |
|
| The preview template data for the specified object, typically loaded from a |
Return Value Example (PreviewTemplate)
Since the exact structure of PreviewTemplate
can vary, here's a common example of what it might contain (as a YAML object):
title: My Awesome Document
description: A detailed description of the document.
icon: https://example.com/icon.png
tags:
- document
- important
- project
links:
- name: View Document
url: https://example.com/document
- name: Download PDF
url: https://example.com/document.pdf
Example#
The following example demonstrates how to retrieve the preview metadata for an object located at my-folder/document/
in your DID Space.
import { DIDSpacesClient } from '@did-space/client';
import { GetPreviewObjectCommand } from '@did-space/client/commands';
async function getObjectPreview(client, folderPath) {
try {
const response = await client.send(
new GetPreviewObjectCommand({
key: folderPath,
})
);
if (response.statusCode === 200) {
console.log('Successfully retrieved preview metadata:');
console.log('Status Code:', response.statusCode);
console.log('Status Message:', response.statusMessage);
console.log('Preview Data:', response.data);
return response.data;
} else {
console.error(`Failed to retrieve preview metadata. Status: ${response.statusCode} ${response.statusMessage}`);
return null;
}
} catch (error) {
console.error('Error retrieving preview metadata:', error);
throw error;
}
}
// Example usage:
// Assumes 'client' is an initialized DIDSpacesClient instance
// const client = new DIDSpacesClient({ ... });
// getObjectPreview(client, 'my-documents/report/');
This example initializes a GetPreviewObjectCommand
with the key
parameter set to the folder path. It then sends the command using the DIDSpacesClient
and logs the retrieved preview data or any errors encountered during the process. The key
should point to the directory where the object resides and where its .meta/preview.yml
file would be located.
This section covered how to retrieve preview metadata for objects in your DID Space. You can use this to display rich previews in applications. Next, learn how to remove preview metadata with the Delete Preview command.