api.getFile()
Description
Allows getting data for a file or folderUsage
getFile: (
id: string
) => {
id: string,
type?: "file" | "folder",
size?: number,
lazy?: boolean,
date?: Date,
parent: string,
name: string,
ext: string,
open?: boolean,
data?: {
id: string,
type?: "file" | "folder",
size?: number,
lazy?: boolean,
date?: Date,
parent: string,
name: string,
ext: string,
$level: number,
open?: boolean,
data?: any[],
[key: string]: any,
}[],
[key: string]: any,
} | null;
Parameters
id- the requested file ID
Returns
Returns IParsedEntity object if a file/folder with the given ID exists, or null if it doesn’t.
An object that is returned has the following parameters:
id– (required) unique identifier of the file or foldertype- (optional) it can be "file" | "folder"` that indicates whether the entity is a file or foldersize– (optional) the size of the file in bytes (folders may omit this)lazy– (optional) iftrue, children are loaded on demanddate– (optional) last modification or creation dateparent– (required) ID of the parent foldername– (required) the name of the file or folderext– (required) file extension; empty string for foldersopen– (optional) whether the folder is expanded in the UIdata– (optional) nested children (if any), each with the same structure asfile[key: string]: any– additional metadata fields provided by the backend
The object that is returned is as in the example below:
data:null
date:Thu Nov 30 2023 06:13:00 GMT+0300 {}
ext:"txt"
id:"/Info.txt"
name:"Info.txt"
parent:"/"
size:1000
type:"file"
Example
<script>
import { Filemanager } from "@svar-ui/svelte-filemanager";
import { getData } from "./common/data";
let api;
function logSelection() {
const id = api.getState().selected[0]; // get selected id
alert(api.getFile(id).name); // show the file name
}
</script>
<Filemanager
bind:this={api}
onselect-file={logSelection} />
Related articles: