Imported images from base64 strings do not display

I use the following code (this is just a part of it), it reads a bunch of json files and creates
the images from the representative strings in the json file.

import os
from plone import api
from Testing.makerequest import makerequest
from plone.namedfile.file import NamedBlobImage
from base64 import b64decode

...
# data comes from a json file 

image_obj = api.content.create(
                        type='Image',  # set the content type
                        container=container,
                        title=name,
                        id=id,
                        **otherdata)

                    image_obj.image = prep_image(
                                            imagename=image_data['filename'],
                                            data=image_data['data'],
                                            content_type=data['_content_type'],
                                           )

def prep_image(imagename, data, content_type ):
        """ load image from data string """
        return NamedBlobImage(
                    data=b64decode(data),
                    contentType=content_type,
                    filename=imagename)

When I attempt to view the image I get the following error:

ERROR root could not scale "<plone.namedfile.file.NamedBlobImage object at 0x10e0c28c0>" of 'http://localhost:8081/Plone/deals/myimage.jpg'

It seems that the default view associated with the images was not working. So browsing a folder and clicking on an image will go to {mysite}/myimage/view which gives the error. Removing the /view and going directly {mysite}/myimage works. so I will need to do some tweaking to figure out what's happening with view (or the image).