Mercurial Hosting > freedit
view src/test/upload.js @ 58:31c895b73bd0
improve change email
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 29 Nov 2022 16:09:17 -0700 |
parents | 1ac7aee13eca |
children |
line wrap: on
line source
function upload(input,callback) { let file = input.files[0]; input.value = null; let request = new XMLHttpRequest(); let url = 'https://upload.uploadcare.com/base/'; request.open( 'POST', url ); request.onload = function() { if( request.status !== 200 ) { let err = 'ajax failed: ' + request.status; if( request.responseText ) { err += '\n' + request.responseText; document.write('<pre>'+request.responseText+'</pre>'); } console.log(err); ajax( '/error_log.js', 'err='+encodeURIComponent(err) ); return; } let response = JSON.parse(request.responseText); let filename = file.name; let url = 'https://ucarecdn.com/' + response.file + '/' + filename; callback(input,url,filename); }; let formData = new FormData(); formData.append( 'UPLOADCARE_PUB_KEY', 'fe3d30f3088a50941d45' ); formData.append( 'file', file ); request.send(formData); } function fileButtonClick(button) { button.parentNode.querySelector('input[type="file"]').click(); }