views:

54

answers:

3

(13, 'Permission denied') error occurs when trying to upload an image in Django i have checked the access rights of the directory in which image will be saved drwxr-xr-x 2 hsrd hsrd 4096 2010-03-19 15:49 media

Please a suggest a solution for this.

if request.method == 'POST':
    if 'file' in request.FILES:
            file = request.FILES["file"]
            fdata = file.read(file.size)
            b = base64.b64encode(fdata)
            from StringIO import StringIO
    content=StringIO(fdata)
    upload_dir = settings.MEDIA_ROOT
            destination =os.path.join(upload_dir, image_name)
    from PIL import Image
        img = Image.open(content)
    image_to_scratch(img,destination)

            return render_to_response('ocr/ocr.html',{
                    'filename':file.name,
                    'hasImage':True,
                    'imgdata':r'data:image/png;base64,' + b

            })
A: 

Your code isnt formatted too well, so i havent read that, but I would recommend checking which user the django instance is running as, if you are deploying with mod_wsgi check out:

http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess

dysmsyd
I am not using mod_wsgi.i tried it with modpython as described in the tutorial http://docs.djangoproject.com/en/dev/howto/deployment/modpython/?from=olddocs
indu
Solved the problem changed the filepath in which image to saved to /tmp
indu
im glad you have solved the problem, but if the images are to be stored permanently /tmp is not the place for them to go!
dysmsyd
A: 

It appears that the user Django is running under is not 'hsrd'. You can:

  • Run Django under the 'hsrd' user (may not be feasible)
  • CHOWN the directory so it belongs to the user Django is running under
  • (Easiest) Chmod 775 the directory
Agos
Thnaks for the answer. I have already tried the 3rd option.Still its not working
indu
A: 

Assuming at @agos is correct, and that you're running this as the "apache" or "httpd" user, a solution that will be reasonably effective is to change the ownership of the directory to the same user that's running the Apache/Modpython processes.

chown -R apache:apache fully_quality_dir_path

should do the trick. Make sure you get the media_root directory and everything underneath it, at least based on your code snippet above.

heckj