Django Image Upload: IOErrno2 Could not find path -- and yet it's saving the image there anyway?
Posted
by Rob
on Stack Overflow
See other posts from Stack Overflow
or by Rob
Published on 2010-04-29T16:57:00Z
Indexed on
2010/04/29
17:07 UTC
Read the original article
Hit count: 341
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 a) it's the wrong error code, or b) 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
m.avatar = upload_photo(request.FILES['avatar'], settings.AVATAR_SAVE_LOCATION) File "/home/user666666/containers/django/leonidas/usertools/functions.py" in upload_photo
destination = open(savePath, 'wb+')
© Stack Overflow or respective owner