> ## Documentation Index
> Fetch the complete documentation index at: https://www.cometchat.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Avatars (Deprecated)

> Avatars (Deprecated) — CometChat documentation.

<Warning>
  Deprecated: This extension is no longer maintained and will not receive further updates.
</Warning>

This extension allows the end-users to upload an avatar image for their profile.

With the Avatars Extension, your users can upload your end-users' avatar directly in CometChat. This extension is useful when you do not have a user profile management feature in your website or mobile app.

<Frame>
  <img src="https://mintcdn.com/cometchat-22654f5b/7-hZ4AEh99NJJtEC/images/9869cdd5-kc6xqiibs2ss2avjcldjtetfmr1ymuhqrzrq60bg7xdwtk8cvvk7qp7vj8knw8q8-98f23edfad7157a5efb995a7a4921f4f.jpeg?fit=max&auto=format&n=7-hZ4AEh99NJJtEC&q=85&s=e34c43583476cc40b7be9c49e7f4f9a5" width="1200" height="675" data-path="images/9869cdd5-kc6xqiibs2ss2avjcldjtetfmr1ymuhqrzrq60bg7xdwtk8cvvk7qp7vj8knw8q8-98f23edfad7157a5efb995a7a4921f4f.jpeg" />
</Frame>

## Extension settings

1. Login to [CometChat](https://app.cometchat.com/login) and select your app.
2. Go to the Extensions section and enable the Avatars extension.

## How does it work?

This extension allows the users to select an image for their avatar on CometChat.

Once the image file is selected for the avatar, it needs to be uploaded in the `base64` format. The extension hosts the image and updates its URL in the avatar section of the user's profile. Also, the avatar URL is sent back in the success response for being updated in your backend.

Image formats allowed by the extension are: `jpg`, `jpeg`, `png`, svg.

Make use of the `callExtension` method provided by the CometChat SDK as shown below.

<Note>
  Max size limit

  The size of the Avatar image file is limited to 2 MB. Please validate the size of the image before uploading it to CometChat via this extension.
</Note>

<Tabs>
  <Tab title="JavaScript">
    ```js theme={null}
    CometChat.callExtension(
      'avatar',
      'POST',
      'v1/upload',
      {
        avatar:
          'data:image/jpeg;base64,abcd',
      }
    ).then(response => {
       // { avatarURL: "https://data-eu.cometchat.io/avatars/photo123.jpg" }
      }).catch(error => {
       // Error occured
    });
    ```
  </Tab>

  <Tab title="Java">
    ```java theme={null}
    import org.json.simple.JSONObject;
    JSONObject body=new JSONObject();

    // bytes refer to the selected image bytes
    String imageString = Base64.encodeToString(bytes, Base64.NO_WRAP);

    // The image type can image/jpg, image/png, etc.
    // based on the image file under consideration.
    body.put("avatar", "data:image/png;base64,abcd"+imageString);

    CometChat.callExtension("avatar", "POST", "/v1/upload", body,
    new CometChat.CallbackListener < JSONObject > () {
        @Override
        public void onSuccess(JSONObject jsonObject) {
            // {avatarURL: "https://data-us.cometchat.io/avatars/1a2b3c.jpg"}
        }
        @Override
        public void onError(CometChatException e) {
            // Some error occured
        }
    });
    ```
  </Tab>

  <Tab title="Swift">
    ```swift theme={null}
    CometChat.callExtension(slug: "avatar", type: .post, endPoint: "/v1/upload", 
      body: ["avatar": "data:image/png;base64,abcd", onSuccess: { (response) in
        // { avatarURL: "https://data-eu.cometchat.io/avatars/1a2b3c.jpg" }
      }) { (error) in
        // Some error occured
      }
    }
    ```
  </Tab>
</Tabs>
