Sending a file to the server using ITSA.Uploader.sendFile().
Click on the button to select and automaticly send the selected file.
Note: this example does not use SPDY. Max uploadsize = 10Mb. Uploaded files will be removed on the server immediately.
Code-example:
<body>
<div id="container">
<button id="button-send" class="pure-button pure-button-primary pure-button-bordered">Click me to upload a file</button>
</div>
<div id="target-container"></div>
</body>
<script src="itsabuild-min.js"></script>
<script>
var url = 'http://somedomain.com.upload',
container = document.getElement('#target-container'),
MB10 = 10*1024*1024,
uploader, writeResponse, errorResponse, progressfn;
writeResponse = function(response) {
container.setHTML('Finished uploading');
};
errorResponse = function(e) {
container.setHTML(e.message || e);
};
progressfn = function(e) {
var percent = Math.round(100*(e.loaded/e.total));
container.setHTML(percent+'% loaded');
};
uploader = new ITSA.Uploader({url: url, options: {progressfn: progressfn}, maxFileSize: MB10});
ITSA.Event.after(
'tap',
function() {
uploader.selectFile({autoSend: true});
},
'#button-send'
);
ITSA.Event.after('uploader:send', function(e) {
var ioPromise = e.returnValue;
ioPromise.then(writeResponse, errorResponse);
});
</script>