Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiple file upload with same key #433

Merged
merged 3 commits into from
Jul 7, 2015
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