Works with any backend npm install Zero dependencies

Custom Response Parser

Parse non-standard server responses with a custom responseParser function.

(function() {
 var logEl = document.getElementById('log');
 function log(m) { var d = document.createElement('div'); d.className='pkg-log-entry'; d.textContent=m; logEl.appendChild(d); logEl.scrollTop=logEl.scrollHeight; }
 new MultipleUpload('#demo', {
 uploadUrl: '/api/upload',
 multiple: true,
 responseParser: function(responseText, task) {
 log('Raw response: ' + responseText.slice(0, 100));
 var data = JSON.parse(responseText);
 return {
 success: data.status === 'ok' || data.success === true,
 fileGuid: data.id || data.fileGuid || data.guid,
 fileName: data.name || task.fileName,
 fileSize: data.size || task.fileSize,
 errorMessage: data.error || data.message || null
 };
 }
 });
})();

Reading your server's reply

responseParser lets you pull the fields you care about out of whatever shape your endpoint returns — a URL, an id, a storage key — instead of forcing the server to match a format the component expects.

It is also where good error messages come from

A failed upload usually carries a useful message in the response body, and without a parser the user sees a status code instead. Extracting your API's error text here turns “HTTP 422” into “that file type is not allowed for this document type”, which is the difference between an error someone can act on and one they cannot.