[Quixote]上傳時錯誤TypeError: coercing to Unicode: need string or buffer, htmltext found
#儲存接收到的圖片
class Save(Directory):
_q_exports = ['']
def _q_index[html](self):
max_size = 10485760
if True:#get_user():
upload = get_field('file')
pos = upload.fp.tell() # Save current position in file.
upload.fp.seek(0, 2) # Go to end of file.
size = upload.fp.tell() # Get new position (which is the file size).
upload.fp.seek(pos, 0) # Return to previous position.
upload.size = size
if size > max_size:
msg = "The uploaded file is too big (size=%s, max=%s bytes)"
msg %= (size, max_size)
raise QueryError(msg)
out = open('/usr/me/2.jpg', 'w')
# Copy file in chunks to avoid using lots of memory.
while 1:
chunk = upload.read(1024 * 1024)
if not chunk:
break
out.write(chunk)
out.close()
upload.close()
將紅色行中的[html]去掉,變成->def _q_index(self):