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.