This question has been flagged
1 Reply
7608 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

Avatar
Discard
Author Best Answer

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

Avatar
Discard
Author

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)