开发者

Django Image Upload: IOErrno2 Could not find path -- and yet it's saving the image there anyway?

I have an issue where the local version of Django is handling image upload as expected but my server is not. Note: I am using a Django Container on MediaTemple.net (grid server)

Here is my code.

def view_settings(request):    
<snip>
if request.POST:
    success_msgs = ()
    mForm = MainProfileForm(request.POST, request.FILES, instance = mProfile)
    pForm = ChangePasswordForm(request.POST)
    eForm = ChangeEmailForm(request.POST)
    if mForm.is_valid():
        m = mForm.save(commit = False)
        if mForm.cleaned_data['avatar']:
            m.avatar = upload_photo(request.FILES['avatar'], settings.AVATAR_SAVE_LOCATION)
        m.save()
        success_msgs += ('profile pictured updated',)
            <snip>

def upload_photo(data,saveLocation):
    savePath = os.path.join(settings.MEDIA_ROOT, saveLocation, data.name) 
    destination = open(savePath, 'wb+')
    for chunk in data.chunks():
        destination.write(chunk)
    destination.close()
    return os.path.join(saveLocation, data.name)

Here's where it gets whacky and I was hoping someone could shed a light on this error, because either

  • it's the wrong error code, or
  • something is happening with the file before it's completely handled.

To recap, the file was actually uploaded to the server in the intended directory - 开发者_运维技巧and yet this err msg continues to persist.

IOError at /user/settings

[Errno 2] No such file or directory: u'/home/user66666/domains/example.com/html/media/images/avatars/DSC03852.JPG'

Environment:

Request Method: POST Request URL: http://111.111.111.111:2011/user/settings Django Version: 1.0.2 final Python Version: 2.4.4 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'ctrlme', 'usertools', 'easy_thumbnails'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware')

Traceback: File "/home/user6666/containers/django/leonidas/usertools/views.py" in view_settings 51. m.avatar = upload_photo(request.FILES['avatar'], settings.AVATAR_SAVE_LOCATION) File "/home/user666666/containers/django/leonidas/usertools/functions.py" in upload_photo 91. destination = open(savePath, 'wb+')

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜