Module-documentation

version 1.0.0
module: itsa-io
maintanance: Marco Asbreuk
home
all modules

IO.sendBlob()

Sending a file to the server using ITSA.IO.sendBlob().

Click on the button to initiate the request.

Note: this example does not use SPDY. Max uploadsize = 10Mb. The uploaded file will be removed on the server immediately.

Code-example:

<body>
    <div id="container">
        <input id="filetosend" multiple type="file">
        <button id="button-send" class="pure-button pure-button-primary pure-button-bordered">Click me to upload the 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'),
        writeResponse, writeResponse, progressfn;

    writeResponse = function(response) {
        container.setHTML(JSON.stringify(response));
    };

    errorResponse = function(e) {
        container.setHTML(e.message);
    };

    progressfn = function(e) {
        var percent = Math.round(100*(e.loaded/e.total));
        container.setHTML(percent+'% loaded');
    };

    ITSA.Event.after(
        'tap',
        function() {
            var fileInput = document.getElement('#filetosend'),
                firstFile = fileInput.files[0],
                sendPromise = IO.sendBlob(url, firstFile, null, {progressfn: progressfn);
            sendPromise.then(writeResponse, errorResponse);
        },
        '#button-send'
    );
</script>
API Docs