Skip to main content

File Upload Plugin

A slick UI component for uploading, viewing and downloading files.

Add a file!

Usage#

/* Editor */
import { RicosEditor } from 'ricos-editor';
import { pluginFileUpload } from 'wix-rich-content-plugin-file-upload';
<RicosEditor plugins={[pluginFileUpload(FileUploadConfig)]} />;
/* Viewer */
import { RicosViewer } from 'ricos-viewer';
import { pluginFileUpload } from 'wix-rich-content-plugin-file-upload/viewer';
<RicosViewer plugins={[pluginFileUpload(FileUploadConfig)]} />;

Config#

upload functions#

handleFileUpload: (files: File[], updateEntity: UpdateEntityFunction) => void
handleFileSelection: (updateEntity: UpdateEntityFunction) => void

handleFileUpload is a function provided to handle media uploads from the native file input.
handleFileSelection is a function provided to handle media uploads from a custom file input.

In both functions when the upload phase is done the updateEntity callback should be called with an object containing the data, error (upon faliure) and index (for multiple file uploads).

UpdateEntityFunction<T>: (data: T, error: MediaUploadError, index: number) => void
data?: {
name: string;
type: string;
url?: string;
id?: string;
privacy?: 'public' | 'private';
}
MediaUploadError?: {
msg?: string | JSX.Element;
key?: MediaUploadErrorKey;
args?: Record<string, string | number>;
}

privacy#

Access control of the uploaded file: either 'public' or 'private'. Whatever value you set here, will be stored in the data of an uploaded file. This parameter is sent into resolveFileUrl, and you can use it when you customize your own resolver.

modify accepted file types#

accept: '*',

lib utility functions#

File extension to file type mapper#

A utility function that maps file extension to file type.
Usage:

import { fileExtensionToType, FileTypes } from 'wix-rich-content-plugin-file-upload/libs/fileExtensionToType';
FileTypes: enum {
IMAGE = 1,
VIDEO,
WORD,
EXCEL,
ARCHIVE,
PDF,
POWERPOINT,
AUDIO,
MISC,
}
fileExtensionToType: (extension: string) => FileTypes