ForgeComponents
en

Components

j-FileReader

jComponent 20 · jcomponent@20 component Example loaded with jComponent 20
  • singleton
  • only for text files

Methods:

  • component.open(opt) - opens file browser
    • opt.multiple {Boolean} enables multiple files (default: false)
    • opt.accept {String} allows only specified content-type (default: undefined)
    • opt.base64 {Boolean} reads a file in Base64 encoding (default: false)
    • NEW: opt.files {HTTP Files} reads files e.g. from Drag & Drop
    • opt.callback {Function(file)} a callback
    • NEW: opt.progress {Function(percentage, file)} optional
var opt = {};
opt.accept = 'text/*';
// opt.files = e.files;
opt.callback = function(file) {
	console.log(file);
};
SETTER('filereader/open', opt);

Use it with <ui-component name="filereader">. 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="filereader"></ui-component>
<a href="javascript:fopen()">OPEN FILE</a>

<script>
	function fopen() {
		var opt = {};
		opt.accept = 'text/*';
		opt.callback = function(file) {
			$(document.body).append('<div><pre><code>{0}</code></pre></div>'.format(JSON.stringify(file, null, '    ').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')));
		};
		SETTER('filereader/open', opt);
	}
</script>