Skip to Content
Menu
This question has been flagged
4 Replies
9381 Views

Using ir.attachment saved one file in new module but its file extension in .bin file

how i can change it extension into given file name and extension ?   

----------------------------------------------------------------------------------------------

Created new module to attach a file by using ir.attachment

when i attaching and downloading are working

but uploaded file is sample.png when i download file name is like okjddnjd.bin.

any solution ? to make same file name(sample.png) when it download..

Avatar
Discard

Your question is not understandable. Please elaborate it and make an example.

@Ermin: He has uploaded an attachment but when he downloads it again it has the file extension .bin. He's wondering why that is happening and how he can fix it because he wants the original filename to be saved ;) @shaneebkan: Is this is a many2many, one2many or simply by uploading an attachment under 'more'? I know I saw some pull request a few days ago to fix this.

Author

it a new module that inherit ir.attachment that many2one

Best Answer

Dear Shaneebkhan,

You should add a field for filename and use it in the filename attribute of the binary field. You can keep this field visible or invisible as per your requirement. The following is the code example for the

class your_class(osv.Model):

_name = "yourclassname"

_description = "yourclassdescription"

_columns = {

'binary_field':fields.binary('Your binary field'),

'filename':fields.char('Filename'),

}

And in the form view in your xml:

<field name="filename" readonly="1" invisible="1"/>

<field name="binary_field" readonly="1" filename="filename"/>

I hope this helps for you.

Thanks & Regards,

Ankit H Gandhi.



Avatar
Discard