File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change 5
5
HTML_CODE
6
6
end
7
7
8
- post '/' do
8
+ post '/upload ' do
9
9
file = params [ 'our-file' ]
10
10
details = {
11
11
:filename => file [ :filename ] ,
24
24
#
25
25
26
26
JS_CODE = <<-JS
27
- document.getElementById('form-id').onsubmit = function (evt) {
28
- var form = document.getElementById('form-id');
29
- var formData = new FormData(form);
30
- var action = form.getAttribute('action');
27
+ var uploadBtn = document.getElementById('upload-button-id');
28
+ uploadBtn.onclick = function (evt) {
29
+ var fileInput = document.getElementById('file-id');
30
+ var file = fileInput.files[0];
31
+ var formData = new FormData();
32
+ var action = '/upload';
33
+ formData.append('our-file', file);
31
34
32
35
var xhr = new XMLHttpRequest();
33
36
xhr.upload.addEventListener('loadstart', onloadstartHandler, false);
87
90
</ head >
88
91
< body >
89
92
< form action ="/ " method ="post " enctype ="multipart/form-data " id ="form-id ">
90
- < input id ="file-id " type ="file " name ="our-file " />
91
- < input type ="submit " value ="Upload! " />
93
+ < p > < input id ="file-id " type ="file " name ="our-file " /> < input type ="button " value ="Upload " id ="upload-button-id " /> </ p >
94
+ < p > < label > Some other field: < input name ="other-field " type ="text " id ="other-field-id " /> </ label > </ p >
95
+ < p > < input type ="submit " value ="Save " /> </ p >
92
96
< script >
93
97
#{ JS_CODE }
94
98
</ script>
You can’t perform that action at this time.
0 commit comments