When porting to python 3, I run into (another) unicode error.
This works with python 2.7, but in python 3 'return NamedBlobImage' gives error:
*** UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
filename is a string, like: '/Users/me/Plone52/zinstance/src/my.theme/src/my.theme/theme/favicon.png'
from plone import api
import os
from plone.namedfile.file import NamedBlobImage
....
....
icon_image.image = load_image(i_image)
def load_image(i_image):
filename = os.path.join(os.path.dirname(__file__), 'theme',
i_image)
return NamedBlobImage(
data=open(filename, 'r').read(),
filename=u'{0}'.format(i_image)
)