# j-Upload

> The component can perform uploading of files.

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

The component can perform __uploading of files__.

- easy and universal usage
- singleton

__Methods__:

```javascript
var opt = {};

// Restricts files according to the content-type
// opt.accept = 'image/*';

// Enables multiple files
// opt.multiple = true;

// IMPORTANT:
// URL address for uploading
opt.url = '/api/upload/';

// A callback
opt.callback = function(response) {

};

opt.error = function(err) {
	// Optional
	// Error handling
};

// Optional, additional request data
opt.data = {};
opt.data.fieldName1 = 'value';
opt.data.fieldName2 = 'value';

// Shows file browser
SETTER('upload/show', opt);
```

Files are uploaded with these names/keys in the form `file1`, `file2`, `file..N`.

Use it with `<ui-component name="upload">`. 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="upload"></ui-component>
<br />
<a href="javascript:uploadfile()">Upload file</a>

<script>
	function uploadfile() {

		var opt = {};

		opt.url = '/api/upload/files/';
		opt.accept = 'image/*';
		opt.multiple = true;
		opt.callback = function(response) {
			console.log(response);
		};
		// opt.error = function(err) {};

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