uploadFile()

Syntax

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

Name
Type
Required
Description

token

string

Yes

The authentication token response from Eueno API when login. After login, this token was saved in local storage with the name “eueno-token".

publicKey

string

Yes

The public key of user.

options

UploadFileOptions

Yes

Type UploadFileOptions has the structure like this:

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.

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:

"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"
}

Last updated