Files

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
ArgumentTypeDescription
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>
ArgumentTypeDescription
core*CoreA MindDrop core instance.
fileFileA file object.
attachedTostring[]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
ArgumentTypeDescription
core*CoreA MindDrop core instance.
id*stringThe 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;
ArgumentTypeDescription
core*CoreA MindDrop core instance.
fileId*stringThe ID of the file to which to add the attachments.
resourceIds*stringThe 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;
ArgumentTypeDescription
core*CoreA MindDrop core instance.
fileId*stringThe 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;
ArgumentTypeDescription
core*CoreA MindDrop core instance.
fileId*stringThe 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
ArgumentTypeDescription
core*CoreA MindDrop core instance.
files*FileReference[]The files to load into the store.

Clears file references from the store and dispatches a files:clear event.

ArgumentTypeDescription
core*CoreA 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
ArgumentTypeDescription
core*CoreA MindDrop core instance.
event*FileEventThe event type to listen for. See the file events section below for available events.
callback*EventListenerCallbackThe 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
ArgumentTypeDescription
core*CoreA MindDrop core instance.
event*FileEventThe event type for which to remove the event listener.
callback*EventListenerCallbackThe callback of the event listener to remove.
NameDataDescription
files:createFileReferenceDispatched when a file is created.
files:update-file-referenceUpdateFileReferenceEventDataDispatched when a file reference is updated.
files:add-attachmentsAddAttachmentsEventDataDispatched when resources are attached to a file reference.
files:remove-attachmentsRemoveAttachmentsEventDataDispatched when resources are removed as attachments from a file reference.
files:replace-attachmentsReplaceAttachmentsEventDataDispatched when a file reference's attached resources are replaced.
files:deleteFileReferenceDispatched when a file is deleted.
files:loadFileReference[]Dispatched when file references are loaded into the store.
files:clearNo dataDispatched when file references are cleared from the store.

UpdateFileReferenceEventData

PropertyTypeDescription
before*FileReferenceFileReference data before it was changed.
after*FileReferenceUpdated file reference data.
changes*FileReferenceChangesThe changes made to the file reference. See below for details.

FileReferenceChanges

PropertyTypeDescription
attachedTostring[]The resource IDs to which the file is attached to.

AddAttachmentsEventData

PropertyTypeDescription
reference*FileReferenceThe file reference to which the resources were attached.
resourceIds*string[]The added resource IDs.

RemoveAttachmentsEventData

PropertyTypeDescription
reference*FileReferenceThe file reference from which the resource attahcments were removed.
resourceIds*string[]The removed resource IDs.

ReplaceAttachmentsEventData

PropertyTypeDescription
reference*FileReferenceThe file reference in which the resources were replaced.
oldResourceIds*string[]The removed resource IDs.
newResourceIds*string[]The added resource IDs.