### File Upload Plugin

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

#### Usage

##### Editor

```tsx widget
import { pluginFileUpload, RicosEditor } from '@wix/ricos';
import React from 'react';

export default () => {
  // @essential-start
  return <RicosEditor placeholder={'Upload a file...'} plugins={[pluginFileUpload()]} />;
  // @essential-end
};
```

##### Viewer

```tsx widget
import '@wix/ricos/css/plugin-file-upload-viewer.global.css';
import '@wix/ricos/css/ricos-viewer.global.css';
import type { RichContent } from '@wix/ricos';
import { pluginFileUploadViewer, RicosViewer } from '@wix/ricos';
import React from 'react';

export default () => {
  // @essential-start
  return <RicosViewer content={content} plugins={[pluginFileUploadViewer()]} />;
  // @essential-end
};

const content = {
  nodes: [
    {
      type: 'FILE',
      id: 'c4fuo30',
      fileData: {
        src: {
          url: 'https://static.wixstatic.com/media/feac6b9cf32640d3ac325c905f2b3786.jpg',
        },
        name: 'image.jpg',
        type: 'jpg',
        size: 150000,
      },
    },
  ],
} as RichContent;
```

#### Config

##### `upload functions`

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

`handleFileUpload` is a function provided to handle media uploads from the native file input. <br>
`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).

```jsx

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`

```jsx
     accept: '*',
```

##### `File extension to file type mapper`

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

```jsx
import { fileExtensionToType, FileTypes } from '@wix/ricos';

FileTypes: enum {
  IMAGE = 1,
  VIDEO,
  WORD,
  EXCEL,
  ARCHIVE,
  PDF,
  POWERPOINT,
  AUDIO,
  MISC,
}

fileExtensionToType: (extension: string) => FileTypes

```
