Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
2771 Zobrazení

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
Zrušit
Nejlepší odpověď

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
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
lis 24
1681
1
lis 24
2193
1
říj 23
2884
3
pro 23
20781
0
kvě 21
7632