ForgeComponents
en

Components

j-Upload

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20

The component can perform uploading of files.

  • easy and universal usage
  • singleton

Methods:

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.

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>