我正在尝试将图像保存在服务器端。我将其作为 base64 字符串接收,因此我先对其进行解码,然后将其保存在数据库中。但是这失败了,所以我检查了服务器错误日志,发现以下错误。日志
[Tue May 21 14:26:38 2013] [error] [client 41.236.182.133] mod_wsgi (pid=4952): Exception occurred processing WSGI script '/root/AR_BROWSER/example/wsgi.py'.
[Tue May 21 14:26:38 2013] [error] [client 41.236.182.133] IOError: failed to write data
我检查了 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()
但我找不到什么问题。知道这个问题的原因是什么吗?!负责保存图像的代码
@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)