Skip to main content
stores

Managing Files

Stores allow you to exchange and save files. In this section, we'll take a closer look at file structures and how to manage them effectively. We'll also cover some best practices when working with Stores.

About Files

Along with a file's main content, additional metadata is stored to allow easy file management. Below is the structure of the metadata associated with each file:

fieldtypeencrypteddescription
infoServerFileInfoyesadditional information assigned by the server e.g. author, creationDate, storeID and fileID
publicMetabinarynoadditional public information about the message, also accessible through Platform REST API
privateMetabinaryyesadditional information about the message
sizenumberyesThe size of file in getBytes
authorPubKeystringyesThe public key of the author of the file
statusCodenumberno0 if the file was decrypted successfully

Listing files

Here's how you can retrieve and list files from a Store:

const files = await Endpoint.connection().context(CONTEXT_ID).store(STORE_ID).getFiles(0, {
pageSize: 100,
sort: 'desc',
})

const decoder = new TextDecoder();
files.readItems.forEach((file) => {
// due to the fact that meta's are stored as binary data we need to decode it:
const privateMeta = decoder.decode(file.privateMeta);
const publicMeta = decoder.decode(file.publicMeta);

console.log({
...file,
publicMeta,
privateMeta
})
})

Deleting Files

Deleting a file is straightforward, but be aware that this action is irreversible:

await Endpoint.connection().context(CONTEXT_ID).stores.deleteFile(FILE_ID);