logo dile-components dile-components

dile-image-uploader

The dile-image-uploader component is a tool to upload images vía Ajax.

Installation

npm i @dile/crud

Usage

Import the dile-image-uploader component.

import '@dile/crud/components/image-uploader/image-uploader.js';

Use the component.

<dile-image-uploader 
  endpoint="/api/board-games/1/upload-card"
  language="es"
></dile-image-uploader>

This component is implemented with the dile-ajax component, so refer to the dile-ajax documentation for more information on configuration requirements.

Properties

Image validation and preview

After selecting a file, the component decodes it in the browser to check that it's a real, non-empty, non-corrupted image before accepting it. If maxFileSize, minWidth, maxWidth, minHeight or maxHeight are set and the image doesn't comply, the selection is rejected and a translated error message is shown, the same way an invalid extension is reported.

Once a valid image is accepted, a thumbnail and a summary (width × height px · file size) are shown below the drop zone, so the user can confirm the file is the expected one before submitting.

Custom Events

The dile-image-uploader component is based on dile-ajax-form, so you can listen to the same custom events documented for that component.