create-file
Description
Fires when creating a fileUsage
"create-file": ({
file: File,
parent: string,
newId?: string,
}) => void | false;
Parameters
The callback of the create-file action takes an object with the following parameters:
file- an object with the file parameters:name(string) - (required) the file namedate(Date) - (optional) the Date object that represents the date of the entitytype(string) - (optional) the type of an entity which can be "file" | "folder"size(number) - (optional) the size of an item in bytesfile- (optional) the file object retrieved after uploading a file; the properties are the same as described here: https://developer.mozilla.org/en-US/docs/Web/API/File#instance_properties
parent- (required) a folder where an item was creatednewId- (optional) an id that is automatically given to a new file
Returning false from the event handler will block the create-file operation, which you can do via the api.intercept() method.
Example
import { getData, getDrive } from "./common/data";
import { Filemanager } from "@svar-ui/react-filemanager";
function init(api) {
api.intercept("create-file", ({ parent, file }) => {
console.log(`${file.name} was created in the ${parent}`);
});
}
export default function App() {
return (
<Filemanager data={getData()} drive={getDrive()} init={init} />
);
}
Related articles: How to access File Manager API