Skip to Content
Menu
This question has been flagged
1 Reply
1689 Views

It seems like a simple process, but clearly it is not. But maybe I'm asking the wrong question.

I am trying to export my products from my Odoo 12 database and import them into my new Odoo 16. The process works fine, except for the product images. 

When I export images from version 12, I get what appears to be a base64-encoded data string for the images. But as soon as I try to import this data, I get this error message: "Found invalid image data, images should be imported as either URLs or base64-encoded data".

There must be an easy way to import product images? If so please help.

Avatar
Discard
Best Answer

Hi,

This code is used for the CSV file importing, so you can export the image field and external_id from v12 after creating a script for importing the images :

Create a wizard and the wizard.py like this

from odoo import models, fields
import base64
import io
import csv


class DynamicImageField(models.TransientModel):
_name = 'import.photo'
_description = 'Import Photo'

file = fields.Binary('File')

def import_photo(self):

csv_data = base64.b64decode(self.file)

data_file = io.StringIO(csv_data.decode("utf-8"))

csv_reader = csv.reader(data_file, delimiter=',')
keys = ['id', 'image'] # these are the csv file header , we only take the external id and the image filed(binary)
file_reader = []
file_reader.extend(csv_reader)
for i in range(len(file_reader)):
field = list(map(str, file_reader[i]))
values = dict(zip(keys, field))
if values:
if i == 0:
continue
else:
product = self.env.ref(values['id'])
product.write({
'image_1920': values['photo']
})

Regards

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 24
151
1
Nov 24
161
1
Oct 23
1180
3
Dec 23
18893
0
May 21
6319