Add Media button of WP_Editor on custom role profile page not working

I have a custom role defined which has a separate profile page in the front-end. In the profile page there is a wp_editor with Add Media button. But the image is not being attached. This is the error seen when uploading the image – Sorry, you are not allowed to attach files to this post.

This is the capability of the custom role:

$  admins = get_role( 'trip_vendor' ); $  admins->add_cap( 'upload_files' ); $  admins->add_cap( 'level_1' ); $  admins->add_cap( 'edit_post' );                                                    $  admins->add_cap( 'edit_posts' );  $  admins->add_cap( 'edit_other_posts' );  $  admins->add_cap( 'publish_posts' );  $  admins->add_cap( 'read_post' );  $  admins->add_cap( 'read_private_posts' );  $  admins->add_cap( 'delete_post' ); $  admins->add_cap( 'can_edit_posts' ); 

This is how the custom role is logged in with ajax:

$  user = $  _POST['user'];         $  pass = $  _POST['pass'];         $  creds = array();         $  creds['user_login'] = $  user;         $  creds['user_password'] = $  pass;         $  creds['remember'] = true;         $  user = wp_signon( $  creds, is_ssl() );         if ( is_wp_error($  user) )          {           $  result['type'] = 'failed';           $  result['message'] = __( 'Incorrect Login Credentials!.', 'wp-travel-engine' );             if ( defined( 'DOING_AJAX' ) && DOING_AJAX )             {                $  result = json_encode($  result);                echo $  result;             }         }         else{             $  _SESSION['login'] = 'login';             $  _SESSION['user'] = $  user;             $  _SESSION['pass'] = $  pass;             $  result['type'] = 'success';             $  result['message'] = __( 'Logging In...', 'wp-travel-engine' );             if ( defined( 'DOING_AJAX' ) && DOING_AJAX )             {                 $  result = json_encode($  result);                 echo $  result;             }         } 

Can someone please provide some guidelines on this?