PutPreviewObjectCommand
PutPreviewObjectCommand
接口用于在指定的空间中上传预览对象。主要功能是将图像、元数据和其他关联资源上传到指定路径,并返回上传结果。
参数类型#
PutPreviewObjectCommandInput#
参数名称 | 类型 | 必要 | 默认值 | 参数说明 |
---|---|---|---|---|
key | string | Y | 无 | 文件夹的路径,必须以 |
data | object | Y | 无 | 预览模板的数据(复杂类型未展开) |
metadata | object | N | {} | 存储元数据,可以选择性提供额外信息 |
hash | string | N | 无 | 对象的 hash 值,为 ipfs cid v1 的 hash |
resources | array | N | [] | 资源列表,每个资源对应一个 key 和 data |
返回类型#
PutPreviewObjectCommandOutput#
字段名称 | 类型 | 必要 | 说明 |
---|---|---|---|
statusCode | number | Y | HTTP 状态码 |
statusMessage | string | N | 状态消息 |
代码示例#
以下是如何使用 PutPreviewObjectCommand
上传预览对象的示例代码:
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);
在这个示例中,我们首先读取用户的空间端点,然后使用该端点和钱包初始化 spaceClient
。接着,我们从本地读取预览对象的数据,并通过 PutPreviewObjectCommand
配置上传参数,最后检查输出并返回上传结果。