# Upload files with UPLOAD() and progress

> Send a FormData to a Total.js @upload route with UPLOAD() and follow the progress.

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

`UPLOAD('POST /url/', formdata, callback, onprogress)` posts a `FormData` (the address starts with the HTTP method, like in `AJAX()`) and calls the callback with the parsed response. The optional fourth argument receives the percentage while the upload runs. Build the `FormData` from a file input (`new FormData()` and `append('file', input.files[0])`); the server side is the `@upload` route of the file upload recipe.

```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>
```
