diff src/site.js @ 33:4fdc4ec0050b

upload with uploadcare
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 01 Aug 2022 22:50:16 -0600
parents 33731231093a
children c8d47981c74f
line wrap: on
line diff
--- a/src/site.js	Fri Jul 29 13:57:20 2022 -0600
+++ b/src/site.js	Mon Aug 01 22:50:16 2022 -0600
@@ -3,7 +3,8 @@
 	let request = new XMLHttpRequest();
 	let method = postData ? 'POST' : 'GET';
 	request.open( method, url );
-	if( postData )
+	let isMultipart = postData instanceof File;
+	if( postData && !isMultipart )
 		request.setRequestHeader( 'Content-Type', 'application/x-www-form-urlencoded' );
 	request.onload = function() {
 		if( request.status !== 200 ) {
@@ -14,7 +15,13 @@
 		}
 		eval( request.responseText );
 	};
-	request.send(postData);
+	if(isMultipart) {
+		let formData = new FormData();
+		formData.append( 'file', postData );
+		request.send(formData);
+	} else {
+		request.send(postData);
+	}
 }
 
 window.onerror = function(msg, url, line, col, error) {