forked from MattStultz/extrusiongen
-
Notifications
You must be signed in to change notification settings - Fork 1
/
upload_bezier_json_file.js
61 lines (46 loc) · 1.46 KB
/
upload_bezier_json_file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* @author Ikaros Kappler
* @date 2013-08-22
* @version 1.0.0
**/
function upload_bezier_json_file( inputFileElement ) {
//window.alert( JSON.stringify(inputFileElement) );
//window.alert( "FileReader=" + FileReader + ", type=" + (typeof FileReader) );
if( typeof FileReader == "undefined" || !inputFileElement.files ) {
window.alert( "Your browser does not support the HTML5 file API!" );
return;
}
if( inputFileElement.files.length == 0 ) {
window.alert( "Please select a file." );
return;
}
// window.alert( inputFileElement.files[0] );
var json_file = inputFileElement.files[ 0 ];
var reader = new FileReader();
reader.onload = function( e ) {
//window.alert( "File uploaded. Value=" + e.target.result );
try {
var bezierPath = IKRS.BezierPath.fromJSON( e.target.result );
setBezierPath( bezierPath );
} catch( e ) {
window.alert( "Error: " + e );
}
/*
// Send to server?
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
};
xhr.open( "POST", "ajax_file_uploader.php" );
xhr.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
xhr.send( "file=" + uncodeURIComponent(e.target.result) );
*/
};
reader.onprogress = function( e ) {
// NOOP
// (display progress?)
};
reader.onerror = function( e ) {
window.alert( "File upload error (code=" + e.target.error.code+")." );
};
reader.readAsBinaryString( json_file );
}