var URL = 'http://localhost/Orthanc/instances'; // Pay attention to same-origin policy var USERNAME = 'alice'; var PASSWORD = 'alicePassword'; $(document).ready(function() { $('#upload').click(function() { var f = document.getElementById('dicom').files; if (f.length === 0) { alert('No DICOM file selected'); } else { var reader = new FileReader(); reader.onload = function() { // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState if (this.readyState === 2 /* HEADERS_RECEIVED */) { var dicom = reader.result; // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Sending_and_Receiving_Binary_Data#Sending_binary_data var xhr = new XMLHttpRequest(); xhr.onload = function(event) { if (xhr.readyState === 4 /* DONE */) { if (xhr.status == 200) { alert('Success!'); } else { alert('Failure'); } } } xhr.open('POST', URL, true); xhr.setRequestHeader('Authorization', 'Basic ' + btoa(USERNAME + ':' + PASSWORD)); xhr.send(new Uint8Array(dicom)); }; } reader.readAsArrayBuffer(f[0]); } }); });