comparison src/test/upload.js @ 40:1ac7aee13eca

test cleanup
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 31 Oct 2022 14:06:58 -0600
parents
children
comparison
equal deleted inserted replaced
39:3354d4ac89f8 40:1ac7aee13eca
1 function upload(input,callback) {
2 let file = input.files[0];
3 input.value = null;
4 let request = new XMLHttpRequest();
5 let url = 'https://upload.uploadcare.com/base/';
6 request.open( 'POST', url );
7 request.onload = function() {
8 if( request.status !== 200 ) {
9 let err = 'ajax failed: ' + request.status;
10 if( request.responseText ) {
11 err += '\n' + request.responseText;
12 document.write('<pre>'+request.responseText+'</pre>');
13 }
14 console.log(err);
15 ajax( '/error_log.js', 'err='+encodeURIComponent(err) );
16 return;
17 }
18 let response = JSON.parse(request.responseText);
19 let filename = file.name;
20 let url = 'https://ucarecdn.com/' + response.file + '/' + filename;
21 callback(input,url,filename);
22 };
23 let formData = new FormData();
24 formData.append( 'UPLOADCARE_PUB_KEY', 'fe3d30f3088a50941d45' );
25 formData.append( 'file', file );
26 request.send(formData);
27 }
28
29 function fileButtonClick(button) {
30 button.parentNode.querySelector('input[type="file"]').click();
31 }