An interface for retrieving and managing file attachements.
Drops can include file attachements. MindDrop creates a FileReference containing metadata about the file for every file attachement.
File references contain a attachedTo property which keeps track of the resources the file is attached to. When the last attachedTo value is removed, the file is automatically deleted.
Retrieves file references by ID. If provided a single ID string, returns the file reference or null if not found. If provided an array of IDs, returns an array of the corresponding file references.
Files.get(id: string | string[]): FileReference | null | FileReferenceMap
| Argument | Type | Description |
|---|---|---|
id* | string | string[] | The ID(s) of the file reference(s) to retrieve. |
Retrieves all file references.
Files.getAll(): FileReferenceMap
Creates a new file reference from a file and dispatches a files:create event. Returns a promise which resolves to the new file reference.
Files.create(core: Core, file: File, attachedTo?: string[]): Promise<FileReference>
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
file | File | A file object. |
attachedTo | string[] | The IDs of the resources to which this file is attached. |
Deletes a file and its reference and dispatches a files:delete event. Returns the deleted file reference.
Files.delete(core: Core, id: string): FileReference
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
id* | string | The ID of the file reference. |
Adds resource IDs to a file reference's attachedTo value and dispatches a files:add-attachments event as well as a files:update-file-reference event. Returns the updated file reference.
Files.addAttachments(core: Core, fileId: string, resourceIds: string[]): FileReference;
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
fileId* | string | The ID of the file to which to add the attachments. |
resourceIds* | string | The IDs of the resources to which the file is attached. |
Removes resource IDs from a file reference's attachedTo value.
If the file reference's attachedTo value becomes empty, the files is deleted.
Dispatches a files:replace-attachments event as well as a files:update-file-reference event unless the file was deleted, in which case a files:delete event is dispatched.
Returns the updated file reference.
Files.removeAttachments(core: Core, fileId: string, resourceIds: string[]): FileReference;
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
fileId* | string | The ID of the file from which to remove the attachments. |
resourceIds* | string[] | The IDs of the resources from which the file was removed. |
Replaces the resource IDs (removing the current ones and adding the given ones) in file reference's attachedTo value.
If resourceIds is an empty array, the file will be deleted.
Dispatches a files:replace-attachments event as well as a files:update-file-reference event unless the file was deleted, in which case a files:delete event is dispatched.
Returns the updated file reference.
Files.replaceAttachments(core: Core, fileId: string, resourceIds: string[]): FileReference;
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
fileId* | string | The ID of the file for which to replace the attachments. |
resourceIds* | string[] | The IDs of the resources to which the file was attached. |
Loads file references into the store and dispatches a files:load event.
Files.load(core: Core, files: FileReference[]): void
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
files* | FileReference[] | The files to load into the store. |
Clears file references from the store and dispatches a files:clear event.
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
Adds file specific event listeners. Equivalent to calling addEventListener directly on core, but provides more advanced type definitions.
Files.addEventListener(core: Core, event: FileEvent, callback: EventListenerCallback): void
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
event* | FileEvent | The event type to listen for. See the file events section below for available events. |
callback* | EventListenerCallback | The callback fired when the event occurs. See the file events section below for the data passed to the callback. |
Removes file specific event listeners. Equivalent to calling removeEventListener directly on core, but provides more advanced type definitions.
Files.removeEventListener(core: Core, event: FileEvent, callback: EventListenerCallback): void
| Argument | Type | Description |
|---|---|---|
core* | Core | A MindDrop core instance. |
event* | FileEvent | The event type for which to remove the event listener. |
callback* | EventListenerCallback | The callback of the event listener to remove. |
| Name | Data | Description |
|---|---|---|
files:create | FileReference | Dispatched when a file is created. |
files:update-file-reference | UpdateFileReferenceEventData | Dispatched when a file reference is updated. |
files:add-attachments | AddAttachmentsEventData | Dispatched when resources are attached to a file reference. |
files:remove-attachments | RemoveAttachmentsEventData | Dispatched when resources are removed as attachments from a file reference. |
files:replace-attachments | ReplaceAttachmentsEventData | Dispatched when a file reference's attached resources are replaced. |
files:delete | FileReference | Dispatched when a file is deleted. |
files:load | FileReference[] | Dispatched when file references are loaded into the store. |
files:clear | Dispatched when file references are cleared from the store. |
| Property | Type | Description |
|---|---|---|
before* | FileReference | FileReference data before it was changed. |
after* | FileReference | Updated file reference data. |
changes* | FileReferenceChanges | The changes made to the file reference. See below for details. |
FileReferenceChanges
| Property | Type | Description |
|---|---|---|
attachedTo | string[] | The resource IDs to which the file is attached to. |
| Property | Type | Description |
|---|---|---|
reference* | FileReference | The file reference to which the resources were attached. |
resourceIds* | string[] | The added resource IDs. |
| Property | Type | Description |
|---|---|---|
reference* | FileReference | The file reference from which the resource attahcments were removed. |
resourceIds* | string[] | The removed resource IDs. |
| Property | Type | Description |
|---|---|---|
reference* | FileReference | The file reference in which the resources were replaced. |
oldResourceIds* | string[] | The removed resource IDs. |
newResourceIds* | string[] | The added resource IDs. |