Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged

all the data printed in the text file are in one line:

The text file was saved as binary file and downloaded.


Sample output:

MarkKim

instead of 

Mark

Kim

But when i'm printing what's inside the textfile it seems fine.. Is there something wrong during encoding? or do I need to add more.. I've been trying this so many times please help. thank you.

CODE:

     textfile = open('Name.txt', 'w')

     textfile.write('%s' % name + "\n")

        with open('Name.txt', 'r') as f_read:

            file_data = f_read.read()

            # print 'file_data', file_data

            data_encode = file_data.encode('utf8').encode('base64')


        values = {

            'name': 'Name.txt',

            'datas_fname': 'Name.txt',

            'res_model': 'ir.ui.view',

            'res_id': False,

            'type': 'binary',

            'public': True,

            'datas': data_encode,


        }


        attachment_id = self.env['ir.attachment'].sudo().create(values)


        # Prepare your download URL

        download_url = '/web/content/' + str(attachment_id.id) + '?download=True'

        base_url = self.env['ir.config_parameter'].get_param('web.base.url')


        return {

            "type": "ir.actions.act_url",

            "url": str(base_url) + str(download_url),

            "target": "new",

        }



Avatar
Zrušit

windows - linux - mac treats newlines separately use \r\n instead of \n

Autor

Thank you so much @F.P. it worked! :)

Related Posts Odpovědi Zobrazení Aktivita
0
zář 17
3642
0
čvn 23
2122
0
bře 15
4695
6
zář 22
67296
1
zář 17
5661