Skip to content

Not able to upload Cognito Hosted UI css.

0

When i try to upload a custom css file for the Cognito Hosted UI, I get an error -

Error Screenshot

I even tried to upload the css template that AWS provides without any changes, and got the same error with that too.

1 Answer
5

I understand you're facing an error when trying to upload a custom CSS file to the Cognito Hosted UI. This error usually occurs based to how the file is being passed to the API.

The error message indicates that there's an issue with the parameter type when uploading your CSS file:

This suggests that the API is expecting a specific format for the file data, but it's receiving something different.

Common Causes and Solutions: Incorrect File Handling: The error mentions Param.imagefile, which suggests the API is expecting the file to be passed as a binary data type (buffer, stream, blob, etc.), not as a file path or string.

API Method: If you're using the AWS SDK, ensure you're using the proper method to read the file before passing it to the API.

Solution Example below using Python SDK

import boto3
import os

cognito_idp = boto3.client('cognito-idp')
css_file_path = './path/to/your/custom.css'

with open(css_file_path, 'rb') as css_file:
    css_content = css_file.read()

params = {
    'UserPoolId': 'your-user-pool-id',
    'ClientId': 'your-client-id',  # Optional - remove if you want to apply to all clients
    'CSS': css_content
}
try:
    response = cognito_idp.set_ui_customization(**params)
    print("UI customization updated successfully!")
    print(response)
except Exception as e:
    print(f"Error updating UI customization: {e}")

Key Points: File Reading: The file is opened in binary mode ('rb') which is crucial for handling CSS files correctly in Python.

CSS Parameter: The CSS content is passed directly as binary data, which matches what the API expects.

Error Handling: The try-except block helps catch and display any errors that might occur during the API call.

This Python implementation should resolve the InvalidParameterType error you were experiencing by correctly handling the CSS file as binary data.

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.