Я устанавливаю среду linux + apache2.2. + Wsgi + python для проверки загрузки файлов.Всего имеется 2 страницы, одна из которых позволяет пользователю выбрать файл для загрузки;Другой способ обрабатывать загрузку файлов.
Ожидаемый результат:
файл загружен с правильным содержимым файла.
Фактический результат:
файл загружен, но содержимое является исходным содержимым файла плюс часть заголовка http и начала/окончание линии.как:
-----------------------------40976349392994148594600211
Content-Disposition: form-data; name="filename"; filename="configure.scan"
Content-Type: application/octet-stream
[original file content]
-----------------------------40976349392994148594600211
Кто-нибудь может дать мой ответ?Я буду глубоко признателен за вашу помощь.
код первой страницы :
output= '<html><head>' +\
'<br>' + \
'</head><body>' + \
'<form name="form1" action=“/dynamic/postuploadfile.py” enctype="multipart/form-data" method=“post”>' +\
'File: <input type="file" name="test" size=50><br />' +\
'<input type=“submit” value="upload"/>' +\
'</form></body></html>'
def application(environ, start_response):
status = '200 OK'
response_headers = [('Content-type', 'text/html'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]
Код второй страницы:
import os
def upload(environ):
# A nested FieldStorage instance holds the file
#fileitem = req.form['file']
data = environ['wsgi.input'].read(int(environ.get('CONTENT_LENGTH','0')))
message = ''
open('uploaded', 'wb').write(data)
message = 'The file was uploaded successfully'
return ( '<html><body>' + message + '</body><html>' )
def application(environ, start_response):
status = '200 OK'
output = upload( environ )
response_headers = [('Content-type', 'text/html'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]