def METHOD_NAME(self, base64_data):
    if base64_data is None:
        data = base64_data
    # Check if this is a base64 string
    elif isinstance(base64_data, str):
        # Try to decode the file. Return validation error if it fails.
        try:
            decoded_file = base64.b64decode(base64_data)
        except TypeError:
            raise serializers.ValidationError(_("Please upload a valid image."))
        # Generate file name:
        file_name = str(uuid.uuid4())[:12]  # 12 characters are more than enough.
        # Get the file name extension:
        file_extension = self.get_file_extension(file_name, decoded_file)
        self.check_file_extension(file_extension)
        complete_file_name = file_name + "." + file_extension
        data = ContentFile(decoded_file, name=complete_file_name)
    else:
        data = base64_data
        file_extension = self.get_file_extension(data.name, data.read())
        if file_extension is None:
            data.seek(0)
            im = Image.open(data)
            file_extension = im.format.lower()
        self.check_file_extension(file_extension)
        data.seek(0)
    return super(Base64ImageField, self).METHOD_NAME(data)