Used to check for browser translation.
用于检测浏览器翻译。
ブラウザの翻訳を検出する

PutPreviewObjectCommand


PutPreviewObjectCommand interface is designed for uploading preview objects within a specified space. Its primary function is to upload images, metadata, and other related resources to a designated path and then provide the upload result.

Parameter Types#

PutPreviewObjectCommandInput#

Parameter Name

Type

Essential

Default Value

Parameter Description

key

string

Y

None

The folder path must end with / 

data

object

Y

None

View the template data (complex types not displayed in detail)

metadata

object

N

{}

Store metadata with the option to include additional information

hash

string

N

None

The hash value of the object, corresponding to the hash of the IPFS CID v1

resources

array

N

[]

A list of resources, with each resource associated with a key and data

Return Type#

PutPreviewObjectCommandOutput#

Field Name

Type

Essential

Explanation

statusCode

number

Y

HTTP Status Codes

statusMessage

string

N

Status Message

Code Example#

Here is a sample code demonstrating how to use PutPreviewObjectCommand to upload a preview object:

const { spaceEndpoint } = await spacesEndpointRepository.readUser(req.user.did);

const spaceClient = new SpaceClient({
endpoint: spaceEndpoint,
wallet,
});

const dataPath = join(process.env.BLOCKLET_APP_DIR, 'logo.png');
const data = fs.createReadStream(dataPath);

const output = await spaceClient.send(
new PutPreviewObjectCommand({
key: '/test-nft/',
data: {
template: 'nft',
did: 'zjduEsT5qiQr72tVtevGG3GwKjV6J4yHR9fy',
name: 'just test',
chainHost: 'https://beta.abtnetwork.io/api/',
image: 'nft.png',
},
resources: [
{
key: '/test-nft/nft.png',
data,
},
],
})
);

if (output.statusCode !== 200) {
logger.error(output);
return res.status(output.statusCode).send(output.statusMessage);
}

return res.send(output);

In this example, we start by obtaining the user's space endpoint, then use it along with the wallet to initialize the spaceClient. Subsequently, we read the data for the preview object from local storage, configure the upload parameters using PutPreviewObjectCommand, and finally, verify the output and return the upload result.

你获得 0 积分