Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

2

How I can save the binary fields in the file system? (I am not referring to the attachments)

By
Fernando La Chica Mera
on 7/27/15, 11:53 AM 829 views

Hello,

    I wish I could save the contents of binary field in the filesystem and in the database only one string reference type is keep.

   I did a debug in the source /web/controllers/main#Binary and I see that the files in Base64 encoded content is uploaded.

    I have also read here https://www.odoo.com/es_ES/forum/help-1/question/save-binary-files-to-a-folder-11522 that it is possible save the attachment in the file system, but I do not mean it. I mean I want to keep all binary fields to the file system to prevent the tables from growing.

    Searching in http://www.odoo-code-search.com/ I found the https://github.com/gsunjka/server-tools/tree/7.0-magento-export/binary_field project I think that does something similar to what i want, but unfortunately, this module does not work in my version 8.0

    Would know me that way I can get my database did not grow disproportionately?

Thank you very much

1

I think this functionality describe above is quite interesting. Anyone else would think? Has anyone tried to implement it?

I create two field on my model like this: nombre_apk_desarrollo = fields.Char(string ="Nombre paquete desarrollo") apk_desarrollo = fields.Binary(compute='_data_get_desarrollo', inverse='_data_set_desarrollo', string=_('File content')) and this is two procedures called by computed field @api.one def _data_get_desarrollo(self): if not self.nombre_apk_desarrollo: return else: value_path = "" value_path = manejoficheros.busca_ruta_configuracion(); filename = value_path + self.nombre_apk_desarrollo try: r = open(filename, 'rb').read().encode('base64') self.apk_desarrollo = r except IOError: _logger.exception('_data_get_desarrollo reading: %s' % filename) @api.one def _data_set_desarrollo(self): if not self.nombre_apk_desarrollo: return else: self.cambiosRealizadosDes = False value_path = "" nombreFicheroAPK = self.nombre_apk_desarrollo extension = self.dime_extension_fichero(nombreFicheroAPK) if (extension[0] != "apk"): raise ValidationError('El fichero de desarrollo introducido no es un apk.') else: value_path = manejoficheros.busca_ruta_configuracion(); #self.busca_ruta_configuracion() filename = value_path + self.nombre_apk_desarrollo validacion = self.comprueba_si_existe_apk(True,nombreFicheroAPK) if (validacion[0] == True): raise ValidationError("El apk indicado ya está asignado a otra aplicación.") else: try: valoresApkDes = AplicacionTemp() with open(filename, 'wb') as fp: bin_value = self.apk_desarrollo.decode('base64') fp.write(bin_value) os.rename(filename,value_path + "des_" + self.nombre_apk_desarrollo) filename = value_path + "des_" + self.nombre_apk_desarrollo #self.nombre_apk_desarrollo = "des_" + nombreFicheroAPK valoresApkDes.nombre_apk_desarrollo = "des_" + nombreFicheroAPK infoAPK = self.dime_informacion_apk(True) #self.version_des = infoAPK[0][0][0] valoresApkDes.version_des = infoAPK[0][0][0] if (self.name == "" or self.name == False): #self.name = infoAPK[0][0][1][0] valoresApkDes.name = infoAPK[0][0][1][0] else: valoresApkDes.name = self.name if (self.imagen == None): path_icono= infoAPK[0][0][2] + "/res/drawable/icon.png" icono_base_64 = self._set_imagen_app(path_icono) #self.imagen = icono_base_64[0] valoresApkDes.imagen = icono_base_64[0] else: valoresApkDes.imagen = self.imagen #self.nombre_paquete_apk_prod = infoAPK[0][0][3] valoresApkDes.nombre_paquete_apk_des = infoAPK[0][0][3][0] #recojo los valores del AndroidManifest.xml para forzar la escritura de estos valores en base de datos en un solo objeto #de esta manera puedo controlar cuando ha terminado de realizarse todos los cálculos que provoca la subida del APK self.valoresApkDes = valoresApkDes self.nombre_apk_desarrollo = valoresApkDes.nombre_apk_desarrollo self.version_des = valoresApkDes.version_des self.name = valoresApkDes.name valoresApkDes.imagen = icono_base_64[0] self.cambiosRealizadosDes = True self.nombre_paquete_apk_des = valoresApkDes.nombre_paquete_apk_des self._elimina_carpeta_temporal(infoAPK[0][0][2]) except IOError: _logger.exception('_data_set_desarrollo writing: %s' % filename)

Fernando La Chica Mera
on 1/15/16, 8:24 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/27/15, 11:53 AM
Seen: 829 times
Last updated: 4/7/16, 1:45 PM