• Hello,

    I have to build api for android app and i’m using json rest api user plugin but now i want to update user avatar but there is no way to update it.

    Please let me know if anyone could help me for the same?

    • This topic was modified 7 years, 5 months ago by rajueww123.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    There is always a way! (almost)

    You need to make a custom endpoint. Through these you can do anything that PHP can do. Just be sure to use adequate security to ensure only those that are permitted can use your endpoint.

    Thread Starter rajueww123

    (@rajueww123)

    I cannot figure out how i could have this functionality because from my android app suppose user has uploaded profile picture so by editing their profile then in wordpress backend their image should be display as their avatar this is the functionality i want but i dont know how i could do this.

    Please let me help regarding the same.

    Thanks,

    • This reply was modified 7 years, 5 months ago by rajueww123.
    • This reply was modified 7 years, 5 months ago by rajueww123.
    Moderator bcworkz

    (@bcworkz)

    The easiest way is to utilize gravatar.com for avatars. From your app, get the user’s email via REST API, then with the email, get the avatar image from gravatar. Otherwise you need a custom endpoint that returns the image URL stored on the server. Your app can then get the image directly from the server using that URL.

    Thread Starter rajueww123

    (@rajueww123)

    Hello,

    I’m not getting you what i want is from app user can update his profile picture and if he update his profile picture i want to change his profile picture in wordpress is well for that user so whether i have to update avatar or i could have other image field in user profile in wordpress backend.

    And also want to know the method to achieve it.

    Moderator bcworkz

    (@bcworkz)

    tl;dr: Anything is possible through custom REST endpoints, but you are better off using gravatar.com. I’m not able to provide any more detail than the following.

    First of all, you’ll need to add functionality to WP to allow managing of avatars within WP itself, disregarding your app for the moment. A profile image field is an obvious approach that is doable. By default this is not supported, but it can be added. Letting random, un-vetted users upload images adds a significant security risk to the site. This is in part why WP relies on gravatar.com for this by default. There could likely be a plugin that does avatars in WP for you. I don’t know of any myself, but it seems like something that would have been developed, search around.

    Once the basic functionality exists in WP itself, you can create custom REST endpoints to manage the same. FAIK, the theoretical plugin I speak of may include REST endpoints, IDK. One way or another, it can be done. I’m unsure of the specifics of transferring an image to WP from a mobile app. Browsers do this automatically, internally. We provide a file field on a form and the selected file ends up in the server’s temp folder. Your app would need to replicate this behavior. Much like how file downloads are managed, I would imagine uploads involve sending appropriate headers along with the file data stream as part of a POST request.

    You are also going to need some functionality to crop and resize images. People are going to try uploading unprocessed 8+MB 16:9 images from their cameras, which of course are inappropriate as avatars. If you were to rely on gravatar, all of these messy details are handled, your app just needs an email address to fetch the image already properly processed.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Update User Avatar Using Json Rest api’ is closed to new replies.