File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
misc-examples/javascript/upload_enroll Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!-- This is an example of a method in which
2
+ an image can be uploaded from the user"s
3
+ local drive, and the image data
4
+ can be extracted using FileReader and
5
+ used in the payload to the enroll endpoint -->
6
+
7
+ < html >
8
+
9
+ < head >
10
+ < title > Kairos Upload - Enroll Example</ title >
11
+ </ head >
12
+ < body >
13
+
14
+ < form method ="post " enctype ="multipart/form-data " id ="imageUploadForm ">
15
+ < input type ="file " id ="imageUpload " name ="imageUpload ">
16
+ < input type ="submit ">
17
+ </ form >
18
+
19
+ < script src ="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js "> </ script >
20
+ < script >
21
+ $ ( "#imageUploadForm" ) . submit ( function ( e ) {
22
+ e . preventDefault ( ) ;
23
+ var input = $ ( "#imageUpload" ) [ 0 ] ;
24
+ var file = input . files [ 0 ] ;
25
+ var reader = new FileReader ( ) ;
26
+ reader . readAsDataURL ( file ) ;
27
+ reader . onloadend = function ( ) {
28
+ var imageData = String ( reader . result ) ;
29
+ // put your keys in the header
30
+ var headers = {
31
+ "Content-type" : "application/json" ,
32
+ "app_id" : "APP_ID" ,
33
+ "app_key" : "APP_KEY"
34
+ } ;
35
+
36
+ var payload = { "image" : imageData , "gallery_name" : "myGallery" , "subject_id" : "mySubjectID" } ;
37
+
38
+ var url = "http://api.kairos.com/enroll" ;
39
+
40
+ // make request
41
+ $ . ajax ( url , {
42
+ headers : headers ,
43
+ type : "POST" ,
44
+ data : JSON . stringify ( payload ) ,
45
+ dataType : "text"
46
+ } ) . done ( function ( response ) {
47
+ console . log ( JSON . parse ( response ) ) ;
48
+ } ) ;
49
+ } ;
50
+ } ) ;
51
+ </ script >
52
+ </ body >
53
+
54
+ </ html >
You can’t perform that action at this time.
0 commit comments