Skip to Content

Contributors

Module for uploading multiple images/attachments to website

Hello,

we are migrating old site (done in WordPress) into Odoo created site. I am 
looking for a way to upload and store multiple images for use in the migrated 
pages/blogs. So far I couldn't find a way to do this but I have a hunch I am 
missing something here :-) Any help is appreciated. Thank you.

Best regards

	Radovan Skolnik



by Radovan Skolnik - 10:46 - 28 Sep 2020

Follow-Ups

  • Re: Module for uploading multiple images/attachments to website
    Thanx for info. What I wanted to achieve was to somehow upload batch of images 
    into website so they could be used in HTML of blog posts we are migrating from 
    old site. Or generally have the option in Media selection dialog in web editor 
    to upload  a batch of images. However I found that this would be rather 
    complicated because the URL of those images would be something like /web/
    image/107007/image.png The number is generated so not much of a prediction 
    where it'd go. 
    
    I solved it in another way. I create a simple module that only contains 
    static/src/img directory with all the images from original blog. That way it 
    was easy to update the HTML content to point to these as the path would be 
    fixed to /module_name/static/src/img/
    
    Still I think it would be beneficial if it was possible to upload media in 
    batch into website editor to be used later because now you have to upload them 
    one by one.
    
    S pozdravom
    
    	Radovan Skolnik
    
    On streda 14. októbra 2020 10:32:23 CEST Daniel Reis wrote:
    
    > For a one time load you could use a single use module with an XML
    
    > data file.
    
    > XML data files are capable of importing directly from files.
    
    > Example:
    
    > https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/data/res_partner_dem
    
    > o.xml#L54 [1]
    
    > 
    
    > You would need to script the XML generation from a directory
    
    > containing the files to import.
    
    > 
    
    > --dr
    
    > 
    
    > 
    
    > On 14/10/2020 08:32, Peter Hahn wrote:
    
    > 
    
    > If I got you right you are asking for a one-time import job for
    
    > migration, not for a front end based user friendly solution, right?
    
    > 
    
    > 
    
    > _______________________________________________
    
    > Mailing-List: https://odoo-community.org/groups/contributors-15 [2]
    
    > Post to: mailto:contributors@odoo-community.org
    
    > Unsubscribe: https://odoo-community.org/groups?unsubscribe [3]
    
    > 
    
    > 
    
    > 
    
    > [1]
    
    > https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/data/res_partner_de
    
    > mo.xml#L54 [2] https://odoo-community.org/groups/contributors-15
    
    > [3] https://odoo-community.org/groups?unsubscribe
    
    
    
    
    

    by Radovan Skolnik - 11:21 - 14 Oct 2020
  • Re: Module for uploading multiple images/attachments to website
    For a one time load you could use a single use module with an XML data file.
    XML data files are capable of importing directly from files.
    Example: https://github.com/odoo/odoo/blob/14.0/odoo/addons/base/data/res_partner_demo.xml#L54

    You would need to script the XML generation from a directory containing the files to import.

    --dr


    On 14/10/2020 08:32, Peter Hahn wrote:
    If I got you right you are asking for a one-time import job for
    migration, not for a front end based user friendly solution, right?


    by Daniel Reis - 10:31 - 14 Oct 2020
  • Re: Module for uploading multiple images/attachments to website
    Hello Radovan,
    
    If I got you right you are asking for a one-time import job for
    migration, not for a front end based user friendly solution, right?
    
    If that’s the case the best way to do it is using the python shell
    interface for odoo and writing import scripts.
    
    Usual way we do stuff like this is to dump data from the old system in
    some structured way (access old DB, export to CSV/XML etc.) and read and
    transform using python scripts.
    
    Example for writing:
    ```
    image_path = "/".join([self.image_base_path, path])
    try:
        with Image.open(image_path) as image:
            buf = io.BytesIO()
            image.save(buf, format=image.format)
            b64_image = base64.b64encode(buf.getvalue())
            return b64_image, basename(image_path)
    except FileNotFoundError as e:
        _logger.warning(
            f"Could not import image {image_path}",
            exc_info=_no_traceback(e))
    
    ```
    
    Attached is a simple script for reading.
    It just reads an image from a custom model. Doesn’t make sence for your
    case, but you can use this as a minimal starting example for the script
    and combine with the above code.
    
    If you use Odoo with buildout simply call:
    `bin/python_odoo <your_script.py> [your script arguments]`
    to run it.
    
    
    regards, Peter
    
    
    
    
    
    
    Am 13.10.20 um 16:36 schrieb Radovan Skolnik:
    
    > Nobody has anything on this? I really hate repetitive tasks - in this case
    
    > uploading images one by one. Isn't there a way for example to import
    
    > attachments? I've seen something like base64 encoding the content of image and
    
    > the provide it as content. But still needs to set Resource Model to ir.ui.view
    
    > which seems to be read only? Am I missing somethin crucial here? Any advice is
    
    > highly appreciated. Thank you.
    
    > Best regards
    
    > Radovan
    
    > On pondelok 28. septembra 2020 10:42:15 CEST Radovan Skolnik wrote:
    
    >> Hello,
    
    >>
    
    >> we are migrating old site (done in WordPress) into Odoo created site. I am
    
    >> looking for a way to upload and store multiple images for use in the
    
    >> migrated pages/blogs. So far I couldn't find a way to do this but I have a
    
    >> hunch I am missing something here :-) Any help is appreciated. Thank you.
    
    >>
    
    >> Best regards
    
    >>
    
    >> 	Radovan Skolnik
    
    > 
    
    > 
    
    > 
    
    > _______________________________________________
    
    > Mailing-List: https://odoo-community.org/groups/contributors-15 [1]
    
    > Post to: mailto:contributors@odoo-community.org
    
    > Unsubscribe: https://odoo-community.org/groups?unsubscribe [2]
    
    > 
    
    > 
    
    > 
    
    > [1] https://odoo-community.org/groups/contributors-15
    
    > [2] https://odoo-community.org/groups?unsubscribe
    
    > 
    

    by Pete Hahn - 09:31 - 14 Oct 2020
  • Re: Module for uploading multiple images/attachments to website
    Nobody has anything on this? I really hate repetitive tasks - in this case 
    uploading images one by one. Isn't there a way for example to import 
    attachments? I've seen something like base64 encoding the content of image and 
    the provide it as content. But still needs to set Resource Model to ir.ui.view 
    which seems to be read only? Am I missing somethin crucial here? Any advice is 
    highly appreciated. Thank you.
    
    Best regards
    
    	Radovan
    
    On pondelok 28. septembra 2020 10:42:15 CEST Radovan Skolnik wrote:
    
    > Hello,
    
    > 
    
    > we are migrating old site (done in WordPress) into Odoo created site. I am
    
    > looking for a way to upload and store multiple images for use in the
    
    > migrated pages/blogs. So far I couldn't find a way to do this but I have a
    
    > hunch I am missing something here :-) Any help is appreciated. Thank you.
    
    > 
    
    > Best regards
    
    > 
    
    > 	Radovan Skolnik
    
    
    
    
    

    by Radovan Skolnik - 04:35 - 13 Oct 2020