@ -259,12 +259,31 @@ export function uploadCompose(files) {
// Account for disparity in size of original image and resized data
// Account for disparity in size of original image and resized data
total += file . size - f . size ;
total += file . size - f . size ;
return api ( getState ) . post ( '/api/v 1 /media', data , {
return api ( getState ) . post ( '/api/v 2 /media', data , {
onUploadProgress : function ( { loaded } ) {
onUploadProgress : function ( { loaded } ) {
progress [ i ] = loaded ;
progress [ i ] = loaded ;
dispatch ( uploadComposeProgress ( progress . reduce ( ( a , v ) => a + v , 0 ) , total ) ) ;
dispatch ( uploadComposeProgress ( progress . reduce ( ( a , v ) => a + v , 0 ) , total ) ) ;
} ,
} ,
} ) . then ( ( { data } ) => dispatch ( uploadComposeSuccess ( data , f ) ) ) ;
} ) . then ( ( { status , data } ) => {
// If server-side processing of the media attachment has not completed yet,
// poll the server until it is, before showing the media attachment as uploaded
if ( status === 200 ) {
dispatch ( uploadComposeSuccess ( data , f ) ) ;
} else if ( status === 202 ) {
const poll = ( ) => {
api ( getState ) . get ( ` /api/v1/media/ ${ data . id } ` ) . then ( response => {
if ( response . status === 200 ) {
dispatch ( uploadComposeSuccess ( data , f ) ) ;
} else if ( response . status === 206 ) {
setTimeout ( ( ) => poll ( ) , 1000 ) ;
}
} ) . catch ( error => dispatch ( uploadComposeFail ( error ) ) ) ;
} ;
poll ( ) ;
}
} ) ;
} ) . catch ( error => dispatch ( uploadComposeFail ( error ) ) ) ;
} ) . catch ( error => dispatch ( uploadComposeFail ( error ) ) ) ;
} ;
} ;
} ;
} ;