77
88module . exports = function upload ( file , AV , saveOptions ) {
99 //use /files endpoint.
10- var self = file ;
1110 var dataFormat ;
12- self . _previousSave = self . _source . then ( function ( data , type ) {
11+ file . _previousSave = file . _source . then ( function ( data , type ) {
1312 dataFormat = data ;
14- return self . _qiniuToken ( type ) ;
13+ return file . _qiniuToken ( type ) ;
1514 } ) . then ( function ( response ) {
16- self . _url = response . url ;
17- self . _bucket = response . bucket ;
18- self . id = response . objectId ;
15+ file . attributes . url = response . url ;
16+ file . _bucket = response . bucket ;
17+ file . id = response . objectId ;
1918 //Get the uptoken to upload files to qiniu.
2019 var uptoken = response . token ;
2120
2221 var data = new FormData ( ) ;
23- data . append ( " file" , dataFormat ) ;
24- data . append ( 'name' , self . _name ) ;
25- data . append ( " key" , self . _qiniu_key ) ;
26- data . append ( " token" , uptoken ) ;
22+ data . append ( ' file' , dataFormat ) ;
23+ data . append ( 'name' , file . attributes . name ) ;
24+ data . append ( ' key' , file . _qiniu_key ) ;
25+ data . append ( ' token' , uptoken ) ;
2726
2827 var promise = new AV . Promise ( ) ;
2928 var handled = false ;
@@ -41,23 +40,23 @@ module.exports = function upload(file, AV, saveOptions) {
4140 }
4241 handled = true ;
4342
44- delete self . _qiniu_key ;
43+ delete file . _qiniu_key ;
4544 if ( xhr . status >= 200 && xhr . status < 300 ) {
4645 var response ;
4746 try {
4847 response = JSON . parse ( xhr . responseText ) ;
4948 } catch ( e ) {
5049 promise . reject ( e ) ;
51- self . destroy ( ) ;
50+ file . destroy ( ) ;
5251 }
5352 if ( response ) {
54- promise . resolve ( self ) ;
53+ promise . resolve ( file ) ;
5554 } else {
5655 promise . reject ( response ) ;
5756 }
5857 } else {
5958 promise . reject ( xhr ) ;
60- self . destroy ( ) ;
59+ file . destroy ( ) ;
6160 }
6261 }
6362 } ;
0 commit comments