diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/upload.js	Mon Oct 31 14:06:58 2022 -0600
@@ -0,0 +1,31 @@
+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();
+}