Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Re: DMS: uploading xml files bypassing svg mimetype

by
Francesco Ballerini
- 06/11/2023 10:22:05
I answer myself: I forgot to install python-magic library which is not mandatory but advised in module documentation. 
It came back to me when I had to solve another issue, then I realized python-magic also helps to correctly compute xml mimetype to "text/xml".

Best Regards
--
Francesco Ballerini

Il giorno sab 4 nov 2023 alle ore 19:57 Francesco Ballerini <francescobl.lavoro@gmail.com> ha scritto:
Dear contributors, 

I am using DMS module on odoo14 to implement some shared backend data storage. 
By the way thanks for sharing this module, it's a powerful resource.

I have succeeded in uploading some XML files by python code and they are uploaded with an "image/svg+xml" mimetype: this is ok but causes "my_file.xml" to be downloaded in .svg format while I need them to be directly downloaded as .xml (extension is correctly computed as xml).

At the moment a simple way to solve this is by inheriting mimetype computing function and forcing mimetype by using context when creating records from code in a specific workflow

@api.depends("content")

def _compute_mimetype(self):

   super(File, self)._compute_mimetype()

   for record in self:

       force_mimetype = self.env.context.get("force_mimetype")

       if force_mimetype:

           record.mimetype = force_mimetype



Actually my guess is that any non-mapped odoo.tools mimetype will lead the "download" button to ignore the mimetype and download file with the proper extension. This also makes me think why "mimetype" has priority over the "extension" for download, but I am more interested to know if there is a proper way to avoid this behaviour.

I am not confident with data upload from code so I am wondering if I'm missing something that can be done only in create method, without having to inherit the module source code.

Best Regards
--
Francesco Ballerini

Reference