Skip to main content

create-file

Description

Fires when creating a file

Usage

"create-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 name
    • date (Date) - (required) the Date object that represents the date of the entity
    • type (string) - (optional) the type of an entity which can be "file" | "folder"
    • size (number) - (optional) the size of an item in bytes
    • file - (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 created
  • newId - (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

<script>
import { getData, getDrive } from "./common/data";
import { Filemanager } from "@wx/svelte-filemanager";

let api;

$: if (api) {
api.intercept("create-file", ({ parent, file }) => {
console.log(`${file.name} was created in the ${parent}`);
});
};

</script>

<Filemanager data={getData()} drive={getDrive()} bind:api />

Related articles: How to access File Manager API