This question has been flagged
7 Replies
20952 Views

I read some question about how to import image from csv files, and i'm trying to implement it.. but because i'm not really good at IT,i dont really know about how to use base64..

i already try to encode image using base64 and base64 give me a very long code.. then i try to copy and paste it in my csv, and when i try to import it, OpenERP refuse it..

do i need to simplified the code or anything?

Avatar
Discard

Can you please share your file with 2/3 records.

Best Answer

Here the complete procedure for Linux users :

1/ import all your products

2/ export your products : this step is mandatory to get the external ID of your product. In my case I exported Name (that is mandatory) and ean13 since the picture's filename was name as follow :

ean13_code.jpg

3/ open your exported file (product.product.csv) with libreoffice and save it again with option "edit filter settings" in order to change the CSV separator to whatever else than ",". This is a little trick to avoid complicated script to deal with record that embed a coma.

4/ use the following script :

    #!/bin/bash
    # Usage : MakeBase64CSV.sh infile.csv outfile.csv
    # infile.csv columns are : externalID, name, filename or identifier
    # infile.csv separator MUST BE |

echo \"External ID\",\"Name\",\"image\" > $2

while IFS="|" read f1 f2 f3; do

    # recopy external ID and name
    echo -n $f1,\"$f2\", >> $2

    #If third column represents the picture's filename (not the key), please use this command
    #cat $(echo ${f3} | tr -d '\r' | tr -d '"') | base64 --wrap=0 >> $2

    #If third column represents the key to match with the filename, please use this command
    cat $(echo ${f3} | tr -d '\r' | tr -d '"').jpg | base64 --wrap=0 >> $2

    #Carrier return at end of line
    echo  >> $2
done < $1

5/ then use your script

./MakeBase64CSV.sh product.product.csv out.csv

In my example, all the pictures are in the same directory.

6/ you can now import your file out.csv into openERP. (Don't forget to change the CSV separator).

7/ If you run into the following error :

field larger than field limit (131072)

Please do the following :

  • modify the file addons/base_import/models.py
  • add the following line at the very begining of the _convert_import_data function :

    csv.field_size_limit(2097152)

  • delete the file addons/base_import/models.pyc

  • restart your server
  • redo the import of your out.csv file
Avatar
Discard

On Odoo v8, the path `csv.field_size_limit(140000000)` should be inserted at the beginning of the function `_read_csv`.

Just made a first use of the above script; but the outfile obtained is appending the external_id of another line (product) at the end of the image field (after the conversion data). ex:/9j/4AAQSkZJRgABAgAAZABkA........................................................__export__.product_template_266861 What is wrong with my data?

What means ' separator MUST BE | ' ?

CSV = Comma-Separated Values. But you must save it separated by "|", not by "," nor ";". You cannot do that in Excel, try LibreOffice Calc.

wORKS AS EXPECTED; THANKS

Best Answer

I had created a free module that can enable you to import product images stored in an accessible url. You basically import the image url for each product and then do a bulk download from the list view.

Check it out from here and let me know if this will simplify your work.

://apps.openerp.com/apps/modules/8.0/product_image_from_url

Avatar
Discard