Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
8589 Lượt xem

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",

        }



Ảnh đại diện
Huỷ bỏ

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

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 9 17
3577
0
thg 6 23
2059
0
thg 3 15
4596
6
thg 9 22
67131
1
thg 9 17
5603