# Files

The Files SDK offers developers the functionality of an encrypted IPFS drive. It creates a list of references and secret keys to files stored on IPFS, where each file is encrypted with its own secret. This way, if one secret key is compromised, there is no compromise of the entire drive.

> Note: The list of files and secrets is only visible to the Wallet.

Here is a step-by-step guide on how to work with files in NotVault using TypeScript:

1. **Import the necessary libraries**:

   ```typescript
   import { NotVault, Files, FileEntry } from '@notcentralised/notvault-sdk';
   ```
2. **Instantiate the NotVault and Files classes**:

   ```typescript
   const vault = new NotVault();
   const files = new Files(vault);
   ```
3. **Add a new file**:

   * Use the `add` method of the `files` instance to add a file to the vault.
   * The method requires the filename and the content of the file. The content should be in Base64 format when dealing with binary data.
   * The method also accepts a callback function that reports the progress of the upload operation.

   ```typescript
   const newFilesList : FileEntry[] = await files.add(
       '... File Name ...', 
       '... Super secret text, usually in Base64 format when dealing with binary data ...', 
       (event: any) => {
           const percent = Math.floor((event.loaded / event.total) * 100);
           console.log(`Progress ${percent}%`);
       }
   );
   ```
4. **Retrieve the contents of a file given its CID**:

   * Use the `get` method of the `files` instance to retrieve a file from the vault using its Content Identifier (CID).

   ```typescript
   const retrievedFile : FileEntry = await files.get(`... File CID in IPFS ...`);
   ```
5. **List all the files linked to a specific wallet**:

   * Use the `list` method of the `files` instance to retrieve a list of all files linked to the specific wallet in the vault.

   ```typescript
   const allFiles : FileEntry[] = await files.list();
   ```
6. **Remove a file from a private list**:

   * Use the `remove` method of the `files` instance to remove a file from the vault using its Content Identifier (CID).

   ```typescript
   const newFilesAfterRemoval : FileEntry[] = await files.remove(`... File CID in IPFS ...`);
   ```

By following these steps, you can manage your files within the NotVault environment securely and efficiently.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.notcentralised.com/sdk/files.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
