Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4060026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:17:09+00:00 2026-05-20T15:17:09+00:00

I am having error after error trying to upload and resize images to s3

  • 0

I am having error after error trying to upload and resize images to s3 with pil and botos3 and the django default_storage. I am trying to do this on save in the admin.

here is the code:

from django.db import models
from django.forms import CheckboxSelectMultiple

import tempfile

from django.conf import settings

from django.core.files.base import ContentFile
from django.core.files.storage import default_storage as s3_storage
from django.core.cache import cache

from datetime import datetime

import Image, os
import PIL.Image as PIL
import re, os, sys, urlparse

class screenshot(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(max_length=200)

    image = models.ImageField(upload_to='screenshots')
    thumbnail = models.ImageField(upload_to='screenshots-thumbs', blank=True, null=True, editable=False)

    def save(self):
        super(screenshot, self).save() # Call the "real" save() method
        if self.image:

            thumb = Image.open(self.image.path)
            thumb.thumbnail(100, 100)

            filename = str(self.slug)

            temp_image = open(os.path.join('tmp',filename), 'w')
            thumb.save(temp_image, 'JPEG')

            from django.core.files import File
            thumb_data = open(os.path.join('/tmp',filename), 'r')
            thumb_file = File(thumb_data)

            new_file.thumb.save(str(self.slug) + '.jpg', thumb_file)


    def __str__(self):
        return self.title

This is just one of the many ways I have tried to get it working, and I either get (2, ‘No such file or directory’) or some other error.

Please can someone help me to get it working. I want it to use the django backend to get the image uploaded to be resized and saved as the thumbnail and then saved. Let me know if you need to know any information. I would be happy to use the django snippet – http://djangosnippets.org/snippets/224/ but I don’t know what data to feed it. I get the same IOErrors and ‘no such path/filename’ even though the main image is uploading to s3 fine. I have also tried things like:

myimage = open(settings.MEDIA_URL + str(self.image)) 
myimage_io = StringIO.StringIO()
imageresize = myimage.resize((100,100), Image.ANTIALIAS)
imageresize.save('resize_100_100_aa.jpg', 'JPEG', quality=75)

It’s been 3 days of looking now so I am starting to go spare! Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T15:17:09+00:00Added an answer on May 20, 2026 at 3:17 pm

    Why don’t you try sorl-thumbnail. It has the exact same interface as the default ImageField django provides and it seems like it would be a lot nicer to work with than the roll-your-own support.

    • Storage support
    • Pluggable Engine support (PIL, pgmagick)
    • Pluggable Key Value Store support (redis, cached db)
    • Pluggable Backend support
    • Admin integration with possibility to delete
    • Dummy generation
    • Flexible, simple syntax, generates no html
    • ImageField for model that deletes thumbnails
    • CSS style cropping options
    • Margin calculation for vertical positioning
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an error where I am not sure what caused it. Here is
I've been running into a problem while trying to delete uploaded images. The error
i'm trying stuff out with xhtml2pdf (aka Pisa 3.0) and django and am having
My users are having an intermittent error when using a Windows Forms application built
I'm having to open the firefox error console, which is kind of annoying.
I am having an VB Script. I need to log the error information in
I am having trouble with modifying a php application to have pagination. My error
Having a heckuva time with this one, though I feel I'm missing something obvious.
I'm trying to upload an iPhone app binary to iTunesConnect and keep getting the
I've looked through several other questions here and on other sites regarding this issue,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.