Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd

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
Annuleer

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

Auteur

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

Gerelateerde posts Antwoorden Weergaven Activiteit
0
sep. 17
3623
0
jun. 23
2117
0
mrt. 15
4683
6
sep. 22
67268
1
sep. 17
5646