Hi there I am trying to save a Model with a ImageField
profile_image_path = os.path.join(settings.PROFILE_IMAGES_PATH, f'temp_profile_image_generated.png')
profile_image.resize((150, 150))
profile_image.save(profile_image_path)
with open(profile_image_path, 'r') as f:
userprofile.avatar = ImageFile(f)
userprofile.save()
I get that the FileSystem now tries to write the temp file to the actual file.
It creates the destination file on disk.
I have set upload_to and that also works as the file is created.
But then when it tries to read the .png I get a charmap error.
'charmap' codec can't decode byte
Is there a way to create the ImageFile without it trying to copy the content. (The charmap error seems to be a python problem with reading pngs although I can't find anything online)
I saw this code
if hasattr(content, "temporary_file_path"):
file_move_safe(content.temporary_file_path(), full_path)
But I don't know how to use this "temporary_file_path"
Thanks :)