0

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

}   

2 Answers 2

0

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?

-1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.