跳至内容
菜单
此问题已终结
1 回复
2653 查看

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.

形象
丢弃
最佳答案

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

形象
丢弃
相关帖文 回复 查看 活动
2
11月 24
1572
1
11月 24
1989
1
10月 23
2730
3
12月 23
20599
0
5月 21
7494