我正在尝试实现一个将文件(图像)上传到运行金字塔的服务器的系统。现在,这段代码给了我一个AttributeError: 'unicode' object has no attribute 'file'
例外:
服务器端:
session = Session()
username = authenticated_userid(request)
if username == None:
return HTTPNotFound()
else:
user = session.query(User).filter(User.username == username).first()
if 'photo.submitted' in request.params:
input_file = request.POST['file_input'].file
tmp = '../static/images/%s' % (session.query(ProfilePic).order_by(-ProfilePic.photo_id).first().photo_id + 1)
open(tmp, 'w').write(input_file.read())
tmp.close()
return Response('OK')
return {}
HTML:
<html>
<body>
<form action="/settings" method="post">
<input type="file" name="file_input" value="Choose image" />
<p><input type="submit" name="photo.submitted" value="Save" /></p>
</form>
</body>
</html>
看起来很简单,但行不通的东西。我试图按照本教程进行操作,但它似乎只适用于视频/音频文件。我怎样才能使这项工作?