Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
use form to upload file in http post request for image/vidao query
Browse files Browse the repository at this point in the history
  • Loading branch information
felix committed Jul 17, 2019
1 parent 06e1a29 commit fce6f1a
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions gnes/client/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,30 @@ def start(self):

async def general_handler(request, parser, *args, **kwargs):
try:
data = await asyncio.wait_for(request.json(), 10)
data = dict()
# # Option 1: uploading streaming chunk data
# data = b""
# async for chunk in request.content.iter_any():
# data += chunk
# self.logger.info("received %d content" % len(data))

# Option 2: uploading via Multipart-Encoded File
post_data = await request.post()
if 'query' in post_data.keys():
_file = post_data.get('query')
self.logger.info("query request from input file: %s" % _file.filename)
data['query'] = _file.file.read()
elif 'docs' in post_data.keys():
files = post_data.getall("docs")
self.logger.info("index request from input files: %d files" % len(files))
data['docs'] = [_file.file.read() for _file in files]

self.logger.info('data received, beigin processing')
resp = await loop.run_in_executor(
executor,
stub_call,
parser([d.encode() for d in data.get('docs')] if hasattr(data, 'docs')
else data.get('query').encode(), *args, **kwargs))
parser([d for d in data.get('docs')] if hasattr(data, 'docs')
else data.get('query'), *args, **kwargs))
self.logger.info('handling finished, will send to user')
return web.Response(body=json.dumps({'result': resp, 'meta': None}, ensure_ascii=False),
status=200,
Expand Down

0 comments on commit fce6f1a

Please sign in to comment.