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

288
Views
Saving file from URLField to ImageField

I'm trying to download my file from URLField and download it to ImageField. What i get is error

 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte

Unicode error hint

The string that could not be encoded/decoded was: �PNG

model:

image = models.ImageField(upload_to='posts/', blank=True)
image_url = models.URLField(null=True, blank=True)

def save(self, *args, **kwargs):
    if self.image_url:
        result = urllib.request.urlretrieve(self.image_url)
        self.image_url = ''
        self.image.save(
            os.path.basename(self.image_url),
            File(open(result[0]))
        )
    super(Post, self).save()
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try this

File(open(result[0], 'rb'))
about 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!