开发者

Why am I getting 'IOError Exception Value: [Errno 2] No such file or directory' When saving file with PIL

开发者 https://www.devze.com 2023-02-17 23:59 出处:网络
I am building a site using Django/Python and there is one page where the user can upload a photo which is then re-sized and saved using the following function:

I am building a site using Django/Python and there is one page where the user can upload a photo which is then re-sized and saved using the following function:

from PIL import Image, ImageFile

def resize(file_to_resize, string_id,):
    parser = ImageFile.Parser()
    while True:
        s = file_to_resize.read(1024)
        if not s:
            break
        parser.feed(s)
    image = pars开发者_如何学运维er.close()
    ms = image.copy()
    size = 320,240
    ms.thumbnail(size, Image.ANTIALIAS)
    ms.save('http://www.mysite.com/site_media/images/profile/' + string_id, "JPEG") `

This worked fine while running locally, but once I uploaded the site to my host and ran it under Apache, I got the following error:

Request Method: POST

Request URL: http://www.mysite.com/saveimage/8/

Django Version: 1.2.1

Exception Type: IOError

Exception Value:

[Errno 2] No such file or directory: u'http://www.mysite.com/site_media/images/profile/8'

Exception Location: /usr/local/lib/python2.6/site-packages/PIL/Image.py in save, line 1299

Python Executable: /usr/languages/python/2.6/bin/python

Python Version: 2.6.6

Also, I am new to web development and Django/Python, this is actually a project I am working on the learn and plan on sharing it with friends and family, so I'm not sure if this is even the best approach when it comes to security and allowing a file to be written directly to the site. Any advice is appreciated.


You have no directory called "http:" in the current directory.

If you're actually trying to save a file over HTTP, this is not how.

0

精彩评论

暂无评论...
验证码 换一张
取 消