Upload User Avatar from android to Wordpress using Rest API

I am developing an android app that give users ability to browse , register, login, post and comment to my wordpress blog using Rest Api .

I am trying now to add a way for users to update their avatars , but i have no idea how to upload media to my blog


add_action('rest_api_init', function () {

  register_rest_route( 'wp/v2', 'upload_image/',array(
                'methods'  = 'POST',
                'callback' = 'upload_image' )); });


function upload_image( $path ) {

    // NO IDEA HERE

}   

Topic rest-api uploads media android Wordpress

Category Web


You can upload media through the REST API, but to associate it with a user you'll need a plugin or your own custom REST Route. Duplicate of: How to change user avatar using REST API?


WordPress has a built-in function Media Handle Permalink that you can use to create an entry of the file in the database. Media Handle Permalink deals with the POST request, writing to storage, and adding the attachment to the database. You can check the link that leads to the WordPress Codex to find out more on its uses.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.