News & Announcements User Community Developer Community

Welcome to the RingCentral Community

Please note the community is currently under maintenance and is read-only.

Search
Make sure to review our Terms of Use and Community Guidelines.
  Please note the community is currently under maintenance and is read-only.
Home » Developers
Update/Upload User Profile Picture
Tags: errors
Mar 9, 2023 at 3:26am   •   1 replies  •  0 likes
Mousa Khalil

Hi, I want to upload and update a user's profile image with no luck, I tried various approaches non work, even the code in the documentation, the code returns "Parameter [image] value is invalid."

Following is my code.

# ----- views.py ----- #
class UpdateUserProfilePicture(APIView):
    permission_classes = [IsAdminUser]
    authentication_classes = [CustomeAuthentication]
    
    def post(self, request, extensionId):
        data = request.data
        file_data = data.pop('image')
        data["image"] = file_data
        res = updateUserProfilePicture(extensionId, data)
        return Response(res)
# ----- api.py ----- #
def updateUserProfilePicture(extensionId, data):
    platform, rcsdk = login()
    imgType = Image.open(BytesIO(data["image"][0].read())).format.lower()
    image = (data["image"][0].name, data["image"][0].read(), f'image/{imgType}')
    builder = rcsdk.create_multipart_builder()
    builder.add(image)
    try:
        request = builder.request(f"https://platform.devtest.ringcentral.com/restapi/v1.0/account/~/extension/{extensionId}/profile-image", 'PUT')
        res = platform.send_request(request)
        return res
    except Exception as e:
        return ({"error": str(e)})


Note that the login function workes fine, abd both platform, and rcsdk, as I managed to upload a greeting with almost the same approach.

1 Answer
answered on Mar 9, 2023 at 11:39am  

There was an issue with the old RingCentral Python SDK. We just updated the SDK that fixed the issue.

Update the RingCentral Python SDK: pip3 install --upgrade ringcentral

And modify your code as follows:

def updateUserProfilePicture(extensionId, data):
    platform, rcsdk = login()
    imgType = Image.open(BytesIO(data["image"][0].read())).format.lower()
    image = (data["image"][0].name, data["image"][0].read(), f'image/{imgType}')
    builder = rcsdk.create_multipart_builder()
    builder.add(image, 'image')
    try:
        request = builder.request(f"/restapi/v1.0/account/~/extension/~/profile-image", 'PUT')
        res = platform.send_request(request)
        return res
    except Exception as e:
        return ({"error": str(e)})

 0



A new Community is coming to RingCentral!

Posts are currently read-only as we transition into our new platform.

We thank you for your patience
during this downtime.

Try Workflow Builder

Did you know you can easily automate tasks like responding to SMS, team messages, and more? Plus it's included with RingCentral Video and RingEX plans!

Try RingCentral Workflow Builder

PRODUCTS
RingEX
Message
Video
Phone
OPEN ECOSYSTEM
Developer Platform
APIs
Integrated Apps
App Gallery
Developer support
Games and rewards

RESOURCES
Resource center
Blog
Product Releases
Accessibility
QUICK LINKS
App Download
RingCentral App login
Admin Portal Login
Contact Sales
© 1999-2024 RingCentral, Inc. All rights reserved. Legal Privacy Notice Site Map Contact Us