# j-FileUploader

> A simple component for uploading files. It supports auto-resizing images.

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

A simple component for uploading files. It supports auto-resizing images.

- __IMPORTANT__: in jComponent v20, the value of `opt.url` must be in the form `POST /url/`

__Configuration__:

- `url {String}` a default URL address for uploading

__Methods__:

- `fileuploader/upload(opt)` shows a file dialog
	- `opt.url {String}` __important__ URL where will be image uploaded
	- `opt.callback(response, errors) {Function}` a callback __important__
	- `opt.multiple {Boolean}` supports multiple files (default: `false`)
	- `opt.progress(percentage)` {Function}
	- `opt.accept {String}` accept type (default: `*/*`)
	- `opt.prefix {String}` a name prefix `<input name="file{0}"` (default: `file{0}`)
	- `opt.files {FileList}` optional (if you use e.g Drag & Drop)
	- `opt.data {Object}` optional, additional custom data `key_string:value_string`
	- `opt.width {Number}` optional, image width
	- `opt.height {Number}` optional, image height
	- `opt.background {String}` optional, background color defined in HEX or can be `transparent`
	- `opt.keeporiginal {Boolean}` optional, prevents for double resizing (default: `false`)
	- `opt.onlylarger {Boolean}` optional, resizes images only larger than `opt.width` or `opt.height`
	- `opt.base64 {String}` optional, it can contain a valid `dataURI` format (required to fill `opt.filename`)
	- `opt.filename {String}` optional, required with `opt.base64` field
	- `opt.quality {Number}` optional, a default JPEG quality (default: `90`)
	- __NEW__: `opt.disproportionate {Boolean}` use `opt.width` or `opt.height` as maximum values

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

Use it with `<ui-component name="fileuploader">`. 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="fileuploader"></ui-component>
<div class="exec link" data-exec="upload">Upload</div>

<script>
	function upload() {

		var opt = {};

		opt.url = '/api/upload/';

		// jComponent v20:
		// opt.url = 'POST /api/upload/';

		// opt.multiple = true;
		// opt.accept = 'text/*';

		opt.callback = function(response, err) {
			console.log(response, err);
		};
		opt.progress = function(percentage) {
			console.log(percentage);
		};

		SETTER('fileuploader/upload', opt);
	}
</script>
```
