'_io.BufferedReader' object has no attribute 'size'

0

In my web application about Django I have this code:

docPDF = open('publicaciones/Dictamen-'+nombreRevista+'.pdf','rb')
dictamen.fileEsp.save(name=final_name,content= docPDF)

However, the last line gives me an error:

  

'_ io.BufferedReader' object has no attribute 'size'

final_name is a String

    
asked by alexander 13.02.2018 в 15:34
source

1 answer

0

According to the documentation , you have to use File to Save in FileField . Therefore, what you should do is:

from django.core.files import File

# ...
docPDF = open('publicaciones/Dictamen-'+nombreRevista+'.pdf', 'rb')
dictamen.fileEsp.save(name=final_name, content=File(docPDF))

And as you can see in the documentation, the class Field does have an attribute size .

    
answered by 13.02.2018 в 20:06