Docs

updateUserProfileImage()

Updates a user's profile image.

function updateUserProfileImage(userId: string, params: { file: Blob | File }): Promise<User>

Warning

Using Backend SDK methods can contribute towards rate limiting. To set a user's profile image, it's recommended to use the frontend user.setProfileImage() method instead.

const userId = 'user_123'
const fileBits = ['profile-pic-content']
const fileName = 'profile-pic.png'
const file = new File(fileBits, fileName, { type: 'image/png' })

const params = {
  file,
}

const response = await clerkClient.users.updateUserProfileImage(userId, params)

console.log(response)
/*
_User {
  id: 'user_123',
  passwordEnabled: false,
  totpEnabled: false,
  backupCodeEnabled: false,
  twoFactorEnabled: false,
  banned: false,
  locked: false,
  createdAt: 1719935072474,
  updatedAt: 1719935170538,
  imageUrl: 'https://img.clerk.com/eyJ...',
  hasImage: true,
  primaryEmailAddressId: 'idn_123',
  primaryPhoneNumberId: null,
  primaryWeb3WalletId: null,
  lastSignInAt: 1719935072492,
  externalId: null,
  username: null,
  firstName: 'Test',
  lastName: 'Clerk',
  publicMetadata: {},
  privateMetadata: {},
  unsafeMetadata: {},
  emailAddresses: [
    _EmailAddress {
      id: 'idn_123',
      emailAddress: 'test@gmail.com',
      verification: [_Verification],
      linkedTo: [Array]
    }
  ],
  phoneNumbers: [],
  web3Wallets: [],
  externalAccounts: [
    _ExternalAccount {
      id: 'idn_123',
      provider: undefined,
      identificationId: undefined,
      externalId: undefined,
      approvedScopes: 'email https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile openid profile',
      emailAddress: 'test@gmail.com',
      firstName: undefined,
      lastName: undefined,
      imageUrl: '',
      username: null,
      publicMetadata: {},
      label: null,
      verification: [_Verification]
    }
  ],
  samlAccounts: [],
  lastActiveAt: 1719935072472,
  createOrganizationEnabled: true
}
*/

Backend API (BAPI) endpoint

This method in the SDK is a wrapper around the BAPI endpoint POST/users/{user_id}/profile_image. See the BAPI reference for more details.

Feedback

What did you think of this content?

Last updated on