# Качване на файлове с UPLOAD() и напредък

> Изпратете FormData към маршрут @upload на Total.js с UPLOAD() и следете напредъка.

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: bg
Content-SHA256: 8545fe35f85a3f0e1e1f87f04246ea1c96cc4795160c764cbc4c9422d619ad75
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

`UPLOAD('POST /url/', formdata, callback, onprogress)` изпраща `FormData` (адресът започва с HTTP метода, както при `AJAX()`) и извиква callback с разчетения отговор. Незадължителният четвърти аргумент получава процента, докато качването върви. Изградете `FormData` от поле за файл (`new FormData()` и `append('file', input.files[0])`); сървърната страна е маршрутът `@upload` от рецептата за качване на файлове.

```js controllers/upload.js
exports.install = function() {
	ROUTE('POST /upload/ @upload <5mb', upload);
};

function upload($) {

	var file = $.files[0];

	file.read(function(err, buffer) {
		$.json({ filename: file.filename, text: buffer.toString('utf8'), title: $.body.title });
	});
}
```

```html public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
	<script>

		var form = new FormData();
		form.append('title', 'My note');
		form.append('file', new Blob(['hello from the browser'], { type: 'text/plain' }), 'note.txt');

		var progress = [];

		UPLOAD('POST /upload/', form, function(response) {
			SET('uploaded', response);
		}, function(percentage) {
			progress.push(percentage);
		});

	</script>

</body>
</html>
```
