question

Mousa Khalil avatar image
Mousa Khalil asked Phong Vu answered

Update/Upload User Profile Picture

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.

errors
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Phong Vu avatar image
Phong Vu answered

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)})
1 |3000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys