I’m trying to save an image at the server side.I recieve it as base64 string so I decode it first and then save it in the database.However this failed, so I checked the server error log and I found the following
[Tue May 21 14:26:38 2013] [error] [client 18.104.22.168] mod_wsgi (pid=4952): Exception occurred processing WSGI script '/root/AR_BROWSER/example/wsgi.py'. [Tue May 21 14:26:38 2013] [error] [client 22.214.171.124] IOError: failed to write data
I checked wsgi.py
import os import sys path = '/root/AR_BROWSER/example' sys.path.append('/root/AR_BROWSER/example') sys.path.append('/root/AR_BROWSER') sys.path.append('/root/AR_BROWSER/example/app') os.environ['DJANGO_SETTINGS_MODULE'] = 'settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
But i can’t find something wrong. Any idea what could be the cause of this issue?!
the code responsible for saving the image
@csrf_exempt def create_app(request): appName = request.POST['name'] user = request.POST['userID'] c = request.POST['category'] i = request.POST['image'] imgdata = base64.b64decode(i) t = datetime.now() filename = t.strftime('test.jpg') with open(filename, 'w') as f: f.write(imgdata) f.close() u=App_User.objects.get(id=user) apps = App.objects.create(name = appName, category=c, user_id = u.id, app_logo=File(filename)) apps.save() return HttpResponse("You created %s." % apps.name)
That message from mod_wsgi with no traceback generally means that the HTTP client closed the connection before all response data could be written back to it by mod_wsgi.
Answered By – Graham Dumpleton
Answer Checked By – Marie Seifert (AngularFixing Admin)