Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
Python Django - Uploading a file from the shell

I am trying to upload a file from a shell to one of my django models in the following manner:

a = Post(name=name, content=content)
a.attachment.save('some.pdf', File(open('some.pdf', 'r')))        

But I keep getting the following error: TypeError: must be convertible to a buffer, not FieldFile. I looked at other posts and could not find any solution that solves this problem.

I am using Python 2.7 and Django 1.10. I would really appreciate any help.

EDIT: The problem was not with the way I was storing the file but was with my post-save signals. Sorry and thanks for your help!

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

try:

f = open('some.pdf', 'r')
a.attachment = File(f)
a.save()
f.close()
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!