uploadFolder()
Syntax
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.
This method also allows uploading multiple files.
Parameters
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.
account
string
Yes
The account address.
options
UploadFolderOptions
Yes
Type UploadFolderOptions
has structure looks as below:
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. After that, we have an exportedKey for encrypt folder that you uploaded.
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:
"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"
}]
Last updated