Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download images #12

Open
mapeal2 opened this issue Jan 4, 2015 · 17 comments
Open

Download images #12

mapeal2 opened this issue Jan 4, 2015 · 17 comments

Comments

@mapeal2
Copy link

mapeal2 commented Jan 4, 2015

Hi Luke,

How can the images be downloaded in the original format? they're downloaded in binary format as of now.

Thanks in advance,
Manuel.

@lukebranch
Copy link

@mapeal2 ,

Unfortunately i'm not sure about that. When you upload your images to Odoo it converts them into Base64 format, and this is the way they are stored in the database.

I believe you would need to create an extension to extend the default image widget to allow for display of the content in your preferred file format (eg. JPG).

As this is related to Odoo core functionality and not the module directly i'd recommend posting this question to help.odoo.com with a detailed description of what you would like to achieve. This way you will be able to pose the question to those more knowledgeable than me in regards to that particular widget.

Please provide me with a link once you create the forum post. I'll follow the post and provide an answer if I come across a workable method in the future.

@eversatis
Copy link

The Multi Image module that Serpent developed support image preview and can be downloaded as jpg original. I use it on OpenERP 7.0 version. Works like a charm. Not sure if that can be a help for the module develop.

https://code.launchpad.net/~serpentcs/openerp-web/multi-image-7.0

@lukebranch
Copy link

@frankmiao2015 ,

Thanks for the link. I've taken a look and it seems that the multi-image-7.0 module has support for storing the images in the local filestore rather than the database. Here's the code:

http://bazaar.launchpad.net/~serpentcs/openerp-web/multi-image-7.0/view/head:/addons/multi_image/controllers/main.py

Basically the module bypasses the database for the image store, so your images are still left in their original upload format and are stored in:

/web/static/src/img/image_multi/{{your file name here}}

I will label this as a feature request and look into adding this functionality at a later date when I can commit the required time to build it.

@mapeal2
Copy link
Author

mapeal2 commented Jan 5, 2015

Hi,

I've posted the question on the forum:

https://www.odoo.com/forum/help-1/question/download-binary-files-with-original-format-72297

I guess the solution has to be found somewhere in the attachments functionality, since the attachments are uploaded in binary format as well, but downloaded in the original format.

Regards,
Manuel.

@lukebranch
Copy link

@mapeal2 ,

thanks, i've subscribed to the forum post. I'll keep digging through the source code until I can find a solution. I'll leave this issue open as a feature request until it has been implemented.

Please also note i've moved the synced sliders over to Slick Slider for now as it has much of the same features and is a more active project:

https://github.com/kenwheeler/slick

I will add a menu in the backend for choosing sliders, and adding slider options in an update soon.

Thanks for the suggestions!

@mapeal2
Copy link
Author

mapeal2 commented Jan 9, 2015

Hi @lukebranch,

I've been investigating how to download binary files in the original format, and after realizing that attachments are stored in the file system with the purpose of leveraging the size of the database, I wonder now if it's more convenient to upload images as attachments instead of binary files. This has the following advantages from my humble point of view:

  • The attachments preview is already implemented with the kanban view.
  • Both files and images could be uploaded as attachments (Attachments button) and then displayed via 2 separate buttons on the product form, one for images and another one for files, the way it's done for projects.
  • The attachment class could be extended to display a "Published" button.
  • .pdfs and other kind of documents could also be available on the shop for download.

Please let me know what you think about my suggestions.

Regards,
Manuel.

@eversatis
Copy link

As well as I know, Odoo can store the attachments in local files rather than database. You can config it by Settings->Technical->Parameters-System parameters. Change ir_attachment.location to file:///filestore, then your attachments would stock in the openerp/filestore folder. But your idea adding Published button for front download is great idea.

Regards

Frank

@mapeal2
Copy link
Author

mapeal2 commented Jan 10, 2015

Hi Frank,

I've double checked that, as per default, attachments are stored in the file system instead of the database. From ir_attachment.py (https://github.com/odoo/odoo/blob/8.0/openerp/addons/base/ir/ir_attachment.py):

"The 'data' function field (_data_get,data_set) is implemented using
_file_read, _file_write and _file_delete which can be overridden to
implement other storage engines, shuch methods should check for other
location pseudo uri (example: hdfs://hadoppserver)
The default implementation is the file:dirname location that stores files
on the local filesystem using name based on their sha1 hash"
(I've checked this also in my own implementations)

I'm trying to point out that it's maybe more convenient to follow the attachments philosophy of storing product images in the file system rather than in the database as binary files, in order to avoid further performance issues if the number/size of the images grow (which is likely to be like that).

Furthermore, I've seen there's another addon planned to be developed in this repository (website_product_attachments) and I was thinking if both images and product documents are uploaded as attachments, they can be distinguished by the extension of the file or even a new field on the attachments form to determine where the attachment must be included (documents or images). On the product form, 2 new buttons can be created to open separately image attachments or document attachments, similarly to how it's done with projects. These buttons would open the attachment kanban view which displays a preview of the images, and from there the standard/extended attachment functionality can be used. On the website side, images and documents could be splitted using the same criteria, and displayed via different templates (carousel template or attachments template).

I thought it was worth pointing out. If I didn't explain myself properly please let me know.

Regards,
Manuel.

@lukebranch
Copy link

@mapeal2 @frankmiao2015 ,

Thanks for all your feedback and ideas. I have been considering whether or not to keep the pictures in the database for a number of reasons, having them stored in the file system in their original format should theoretically allow people to use server-side optimisation for images like ngx_pagespeed among other things, while having them stored in the database allows for easier backups, scaleability and optimisations on image dimensions, on the fly in python (eg. serving a different image for retina/2x screens).

Both have their pros and cons, so I may provide both as options and allow for people to choose to switch between one or the other in the admin backend:

  1. Store in database and allow for download > save as to download an image in it's original format from the database
  2. Store images in a specified module directory in the filesystem

I will look into implementing the database option first as the basic framework is already there, and will work on implementing the second option once I can find some time.

Please feel free to suggest more features/ideas and i'll work on implementing them as soon as possible.

@mapeal2
Copy link
Author

mapeal2 commented Jan 10, 2015

Thanks @lukebranch !

@mapeal2
Copy link
Author

mapeal2 commented Jan 17, 2015

@lukebranch
There seems to be an open issue with binary fields:
odoo/odoo#3792
I was testing with Firefox when I posted my comments on this issue, but now I've double checked with Chrome and I'm able to download the decoded file although the original file name is not correct. Hope this helps.

@mapeal2
Copy link
Author

mapeal2 commented Jan 17, 2015

And another one:
odoo/odoo#1239

@andreparames
Copy link

Hi, just wanted to point out that the last issue you linked has a pull request associated that fixes the file name issue: odoo/odoo#1241

Still not merged, alas, but you can apply the patch by saving it on a text file and doing git apply <patch file> from inside the Odoo directory.

@lukebranch
Copy link

@andreparames ,

Thanks for the update. I'll take a look at patching this on a development instance and look forward to this being patched further upstream.

@lukebranch
Copy link

Sorry for not replying on this thread, I have been very busy recently with other projects. I plan to work on this project heavily as soon as I can find time, as there are a number of features that i'd like to implement from suggestions from the community.

@dhmetros
Copy link

I'm not sure I understand what odoo/odoo#1239 is referring to and how it's related to this request. I guess I need a better example to understand and reproduce it.

In any case, what I can tell you is binary downloads with file names work in form views. They worked in 7, and they seem to work the same way in 8.

Binary downloads in list/tree views (inside a form at least) are borked, though. They work, but they behave differently than in form views, and, if possible, should probably be re-worked to behave more like they do in form views. (They download all the data and "attach" it as a local download link with a generic mimetype and what ends up being an incomprehensible download file name. The filename is there in the link, but the download doesn't use that info.)

Even if they fixed the file name and mimetype issues, it really shouldn't download all the attachments in the list. IMO, they should behave the same way they do in form views.

So, until they fix that, this would be my recommendation (for binary field storage):

  1. Add a field for the image's file name. You'll probably need this one way or another anyways.
  2. Add a form view after the kanban view definition in the product form. Make sure you add both the image and image filename fields, with the filename='filename_field' attribute set on the image field, like the samples given in the issue/forum posts.
  3. Do the same after the tree view in the product template form. Change the tree view so it's not bottom-editable (that it opens a form instead of inline editing), and maybe show the file name field in the tree view and not the image field (so you don't have people complaining about it not working right; you might have people complaining anyways, but there's not much you can do about that).

Other possible alternatives, which I haven't explored, are adding a button that triggers a download, a custom widget, or qweb template. But, I would save those for another time, when you feel like diving a little deeper and experimenting with it.

Anyways, good work so far!

@lukebranch
Copy link

@dhmetros ,

Thanks for the suggestions, i'll definitely look into implementing the ideas in some form. Currently I am waiting for another module being ported to 8.0 from the OCA called product_images which handles multiple product images related to a product very nicely and allows for storage in filesystem, database, or external link, and generally handles the whole multi-image storage for products far better than this module's framework.

I plan to use this (product_images) module as a basis for storing the product images, and will then re-write my module to pull the images from the one2many in this module.

With the option to store images in the filesystem this will improve performance and allow for more flexible/interesting caching solutions and better handling for CDN's.

Currently I do not have much time to work on it due to other commitments, however I will start work on this module again after the product_images module has been fully ported to 8.0 and is available in the OCA repository here:

https://github.com/OCA/product-attribute

You can track the progress here:

OCA/product-attribute#57

and here:

OCA/product-attribute#42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants