# uploadFolder()

## Syntax

```javascript
uploadFolder(token: string, publicKey: string, account: string, options: UploadFolderOptions)
```

Method to upload a folder in the project. We have two types to upload: encrypted and unencrypted. If you upload a file with encrypt type, you will need to generate a key to encrypt data. See how to generate a key in [this](/eueno-libraries/eueno-lib-browser/create-key-generate-a-key-for-encrypting-the-file-s.md).

This method also allows **uploading multiple files**.

## Parameters

<table><thead><tr><th width="123">Name</th><th width="200">Type</th><th width="108">Required</th><th>Description</th></tr></thead><tbody><tr><td>token</td><td>string</td><td>Yes</td><td>The authentication token response from Eueno API when login. After login, this token was saved in local storage with the name “eueno-token".</td></tr><tr><td>publicKey</td><td>string</td><td>Yes</td><td>The public key of user.</td></tr><tr><td>account</td><td>string</td><td>Yes</td><td>The account address.</td></tr><tr><td>options</td><td>UploadFolderOptions</td><td>Yes</td><td></td></tr></tbody></table>

Type `UploadFolderOptions` has structure looks as below:

```javascript
export const UPLOAD_TYPE = ["UNENCRYPTED", "ENCRYPT"];
export type UploadType = typeof UPLOAD_TYPE[number];
export interface UploadFolderOptions extends Omit<UploadOptions, "file"> {
  files: FileList | File[];
}

interface UploadOptions {
  file: File;
  path: string[]; // Path file
  projectId: string;
  uploadType: UploadType; //"UNENCRYPTED" : "ENCRYPT"
  inFolder: boolean; // true - if upload folder, false - if upload file(s)
  exportedKey?: string; // Need if encrypt
  onUploadProgress: () => void; // Progress upload file,
  account: string;
}
```

## Example

This example describes how to upload folder encrypt in Eueno. First, you need to generate a key (`exportedKey` parameter) to encrypt (if `uploadType` is unencrypted, we will don’t need the key). See how to generate a key in [Create key](https://app.gitbook.com/o/-MWcR8FSKZBU6KvaxcLP/s/QRsOb8nybzYU151xljhX/~/changes/18/library/frontend/create-key-generate-a-key-for-encrypting-the-file-s). After that, we have an exportedKey for encrypt folder that you uploaded.

```javascript
import { uploadFolder } from "@eueno/lib-browser";
import { toast } from "react-toastify";

const onSubmit = async () => {
await uploadFolder(
     token, 
     publicKey, 
     account, 
     {
       files, 
       path: currentPathArray, // [“112”, “Parent Folder”]
       projectId, //112
       uploadType: "ENCRYPT",
       inFolder: false,
       exportedKey, //"TOAp0nl_s84zhFUFNWbsM8utw6zxm3BhG_7qg4CDjO8"
       onUploadProgress: (progressEvent, name) => {},
     toast,
   });
 };

```

Response of example uploaded an image file by encrypt method:

```javascript
 "data": [{
        "id": "220326",
        "name": "Key.svg",
        "nameNo": 1,
        "virtualPath": "0x6c00ba5420f8f86dd26a604f856821c260f1a093/Folder/NewFolder/Profile 3/Key.svg",
        "virtualCloudPath": "0x6c00ba5420f8f86dd26a604f856821c260f1a093/Folder/NewFolder/Profile 3/1678354468130-kwznc.Key.svg",
        "path": "0x6c00ba5420f8f86dd26a604f856821c260f1a093/Folder/encrypt/NewFolder/Profile 3/1678354468130-kwznc.Key.svg",
        "url": "https://node1-gateway-ipfs.eueno.io/ipfs/QmUS4M6VjNKPSrqhcHQCyvemi5jccLPhZUkTj1obysn8Qa",
        "backupUrl": "https://node1-gateway-ipfs.eueno.io/ipfs/QmUS4M6VjNKPSrqhcHQCyvemi5jccLPhZUkTj1obysn8Qa",
        "size": "722",
        "mimeType": "image/svg+xml",
        "method": "ENCRYPT",
        "torrentSize": 4,
        "torrentUrl": "https://node1-gateway-ipfs.eueno.io/ipfs/QmeBHS28FyFB5hrvhu9Mr6wV9YTm499ao2ebR77z4M6yCh",
        "backupTorrentUrl": "https://node1-gateway-ipfs.eueno.io/ipfs/QmeBHS28FyFB5hrvhu9Mr6wV9YTm499ao2ebR77z4M6yCh",
        "encryptKey": "dbdea7cc6fe82d7ad3910fbe31686d3b9f70a4ccf6b304795ecd4806d022a887f6c0c89add138bf03c4a058831b0055c80dd456947f94ef412ed4e1a420b0c6fcd2fb94e2902430e0e4880c88d5b1e756eb3f19b29c2853c9c5352eb17832bc62ea118525fa75ca8459c801177373e9c@@04efe2a4c31c7703c7472da27be78f2bf01d4d9a926f964355837fc9455ba10f220b99b929043683315b3da74e5c77ea9d661b8f7f1080b319ad991a4159b98b98@@bb4dffe2a7507b6cb252a39676dbd096@@2b9e93ff273735e51e34df3e864b2ea000568f0e61640e7b1695672aa0aeac05",
        "createdAt": "2023-03-09T09:34:29.181Z",
        "updatedAt": "2023-03-09T09:34:31.637Z"
    }]

```


---

# 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.eueno.io/eueno-libraries/eueno-lib-browser/uploadfolder.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.
