Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ def post(self):
}

out = MultiDict()
_count = 1
for field in fs.list or ():
transfer_encoding = field.headers.get(
hdrs.CONTENT_TRANSFER_ENCODING, None)
Expand All @@ -370,7 +371,8 @@ def post(self):
field.type)
if self._post_files_cache is None:
self._post_files_cache = {}
self._post_files_cache[field.name] = field
self._post_files_cache[field.name+str(_count)] = field
_count += 1
out.add(field.name, ff)
else:
value = field.value
Expand Down
27 changes: 27 additions & 0 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,33 @@ def go():

self.loop.run_until_complete(go())

def test_files_upload_with_same_key(self):
@asyncio.coroutine
def handler(request):
data = yield from request.post()
files = data.getall('file')
for _file in files:
self.assertEqual(_file.file.closed, False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use self.assertFalse

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like check for file content for example.
Say, on first cycle iteration it should be b'binary data 1' and for second pass b'binary data 2'

resp = web.Response(body=b'OK')
return resp

@asyncio.coroutine
def go():
_, _, url = yield from self.create_server('POST', '/', handler)
_data = FormData()
_data.add_field('file', b'binary data 1',
content_type='image/jpeg',
filename='test1.jpeg')
_data.add_field('file', b'binary data 2',
content_type='image/jpeg',
filename='test2.jpeg')
resp = yield from request('POST', url, data=_data,
loop=self.loop)
self.assertEqual(200, resp.status)
resp.close()

self.loop.run_until_complete(go())

def test_post_files(self):

here = os.path.dirname(__file__)
Expand Down