Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

DMS: uploading xml files bypassing svg mimetype

by
Francesco Ballerini
- 04/11/2023 19:57:11
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

Follow-Ups