File tree Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Expand file tree Collapse file tree 2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 11root = true
22
3- [* .php ]
3+ [* .{ php,html} ]
44indent_style = space
55indent_size = 4
66end_of_line = lf
Original file line number Diff line number Diff line change 2727 < fieldset >
2828 < legend > Client Upload Demo</ legend >
2929 < input name ="file " type ="file ">
30- < input name ="policy " type ="hidden " id ="policy ">
31- < input name ="signature " type ="hidden " id ="signature ">
32- < input type ="submit " value ="submit " class ="submit " id ="submit ">
30+ < input type ="button " value ="submit " class ="submit " id ="upload ">
3331 </ fieldset >
3432</ form >
3533
3634< script >
3735 // 文件保存的路径
3836 var save_path = '/test/filename.txt' ;
39- // 获取 policy 和 secret
40- $ . getJSON ( 'http://localhost:9000/policy.php?save_path=/test/filename.txt' , function ( data ) {
41- document . getElementById ( 'policy' ) . value = data . policy ;
42- document . getElementById ( 'signature' ) . value = data . signature ;
37+ $ ( '#upload' ) . on ( 'click' , function ( ) {
38+ // 获取 policy 和 secret
39+ $ . getJSON ( 'http://localhost:9000/policy.php?save_path=' + save_path , function ( data ) {
40+ var uploadData = new FormData ( $ ( '#demoForm' ) [ 0 ] ) ;
41+ uploadData . append ( 'policy' , data . policy ) ;
42+ uploadData . append ( 'signature' , data . signature ) ;
43+ $ . ajax ( {
44+ url : '//v0.api.upyun.com/sdkimg' ,
45+ type : 'POST' ,
46+ data : uploadData ,
47+ cache : false ,
48+ processData : false ,
49+ contentType : false ,
50+ } ) . done ( function ( data , textStatus ) {
51+ alert ( 'upload success' ) ;
52+ } ) . fail ( function ( res , textStatus , error ) {
53+ try {
54+ var body = JSON . parse ( res . responseText ) ;
55+ alert ( 'error: ' + body . message ) ;
56+ } catch ( e ) {
57+ console . error ( e ) ;
58+ }
59+ } ) ;
60+ } ) ;
4361 } ) ;
4462</ script >
4563</ body >
You can’t perform that action at this time.
0 commit comments