# j-ImageUploader

> A simple singleton component for uploading of resized images. The component uploads base64 according to the schema defined in options of caller.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: b13d50455eb04111ecc37861a865794402c64a99d66c54787308acb66cb010b1
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: components@910ed1a86f6e72b4f031d3ad0dc7844f9fc5cb8e
Review: not-recorded

A simple singleton component for uploading of resized images. The component uploads base64 according to the `schema` defined in `options` of caller.


__Methods__:

- `imageuploader/upload(opt)` shows a file dialog
	- `opt.width {Number}`
	- `opt.height {Number}`
	- `opt.background {String}` a default background color (__NEW__: supports the `transparent` value and output will be `.png`)
	- `opt.url {String}` __important__ URL where will be image uploaded
	- `opt.multiple {Boolean}` supports multiple files (default: `false`)
	- `opt.schema {String}` default `{ file: base64, name: filename }`
	- `opt.quality {Number}` default `90`
	- `opt.callback(response, errors)` a callback __important__
	- `opt.keeporiginal {Boolean}` keeps the original image if the dimension is the same as the width/height defined in the configuration (default: `false`)
	- __NEW__ `opt.files` {FileList} optional (if you use e.g Drag & Drop)

__Friendly components__:
This component works with `loading` when the file is uploading.

Use it with `<ui-component name="imageuploader">`. When the component is not loaded yet, jComponent downloads it on first use from the address in `DEF.fallback` (the Componentator CDN by default). Author: Peter Širka. Source: the Componentator components repository, MIT license.

```html example.html
<ui-component name="imageuploader"></ui-component>
<div onclick="uploadphoto()">Click to upload</div>

<script>

	function uploadphoto() {
		var opt = {};
		opt.width = 200;
		opt.height = 200;
		opt.url = '/api/upload/base64/';
		opt.background = '#FFFFFF';
		opt.multiple = true;
		opt.callback = function(response, err) {
			console.log(response, err);
		};
		SETTER('imageuploader/upload', opt);
	}

</script>
```
