# uploadFile()

## Syntax

```javascript
uploadFile(token: string, publicKey: string, options: UploadFileOptions)
```

The method used to upload files in Eueno. We have two types to upload are encrypted and unencrypted.

## Parameters

<table><thead><tr><th width="144">Name</th><th width="173">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>options</td><td>UploadFileOptions</td><td>Yes</td><td></td></tr></tbody></table>

Type `UploadFileOptions` has the structure like this:

```javascript
interface UploadOptions { 
 file: File;
 path: string[]; // Path file
 projectId: string;
 uploadType: UploadType;
 inFolder: boolean;
 exportedKey?: string; // Need if encrypt
 onUploadProgress: () => void; // Progress upload file,
 account: string;
}

export interface UploadFileOptions extends UploadOptions {
 isLargeFile?: boolean; // file's size > 20MB
 chunkSize?: number; // size of each chunk part, recommend 5MB
 uploadUrl?: UploadUrl; // must be ignored when uploading a single file
 callback?: (
   bufferData: BufferData,
   webseed: string[],
   account: string
 ) => void; // callback must be ignored when uploading a single file
}
```

## Example

Example using ReactJS with Axios. Assuming that, you have a project named Project1 with id is “112”, inside this project we have Folder1, and inside Folder1 we have Folder2. So the path is like this: Project1/Folder1/Folder2. The code below shows how to upload a file by encrypt method in Folder2.

```javascript
import {uploadFile as uploadFileLibrary} from "@eueno/lib-browser";

const uploadFile = async () => {
   const file = files[0];
   
   await uploadFileLibrary(token, publicKey, {
     exportedKey,
     file: file,
     path: [“112”, “Folder1”, “Folder2”],
     projectId: “112”,
     uploadType: "ENCRYPT",
     inFolder: false,
     account,
     onUploadProgress: (progressEvent, name) => {},
   });
 };

```

Response of example:

```javascript
"data": {
        "id": "246203",
        "name": "images (3).jpeg",
        "url": "https://node1-gateway-ipfs.eueno.io/ipfs/Qmf7g...TYaLoA6pbJ3",
        "backupUrl": "https://node1-gateway-ipfs.eueno.io/ipfs/Qmf7gT1HkP...6pbJ3",
        "size": "5650",
        "mimeType": "image/jpeg",
        "method": "UN_ENCRYPT",
        "torrentSize": 4,
        "torrentUrl": "https://node1-gateway-ipfs.eueno.io/ipfs/QmbHg6cV...qmBNQz4U",
        "backupTorrentUrl": "https://node1-gateway-ipfs.eueno.io/ipfs/QmbHg6...qmBNQz4U",
        "encryptKey": null,
        "createdAt": "2023-04-12T09:19:46.721Z",
        "updatedAt": "2023-04-12T09:19:46.938Z"
}
```


---

# 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/uploadfile.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.
