File tree 2 files changed +26
-8
lines changed
2 files changed +26
-8
lines changed Original file line number Diff line number Diff line change 1
1
root = true
2
2
3
- [* .php ]
3
+ [* .{ php,html} ]
4
4
indent_style = space
5
5
indent_size = 4
6
6
end_of_line = lf
Original file line number Diff line number Diff line change 27
27
< fieldset >
28
28
< legend > Client Upload Demo</ legend >
29
29
< 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 ">
33
31
</ fieldset >
34
32
</ form >
35
33
36
34
< script >
37
35
// 文件保存的路径
38
36
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
+ } ) ;
43
61
} ) ;
44
62
</ script >
45
63
</ body >
You can’t perform that action at this time.
0 commit comments