Skip to content

Commit

Permalink
Merge pull request #299 from phenobarbital/dev
Browse files Browse the repository at this point in the history
added form_data to handle uploads
  • Loading branch information
phenobarbital authored Sep 27, 2024
2 parents b4ad2e6 + b571891 commit 4d64727
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
13 changes: 13 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,16 @@ include README.md
global-include *.typed
recursive-include navigator/templates *
recursive-include navigator/static *
# Exclude directories
prune videos
prune examples
prune docs
prune documents
prune etc
prune env
prune resources
prune dist

# Optionally, you can also specify any other unwanted directories
prune tests
prune *.egg-info
2 changes: 1 addition & 1 deletion navigator/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__description__ = (
"Navigator Web Framework based on aiohttp, " "with batteries included."
)
__version__ = "2.10.23"
__version__ = "2.10.24"
__author__ = "Jesus Lara"
__author_email__ = "jesuslarag@gmail.com"
__license__ = "BSD"
12 changes: 8 additions & 4 deletions navigator/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,12 @@ async def handle_upload(
status=406,
content_type='application/json'
)
form_data = {}
uploaded_files = []
try:
reader = await request.multipart()
except KeyError:
return {'error': 'No file uploaded'}
raise FileNotFoundError("No File Uploaded")

# Process each part of the multipart request
async for part in reader:
Expand Down Expand Up @@ -521,9 +522,12 @@ async def handle_upload(
break
f.write(chunk)
uploaded_files.append(temp_file_path)
if not uploaded_files:
return {'error': 'No file uploaded'}
return {'files': uploaded_files}
else:
# If it's a form field, add it to the dictionary
form_field_name = part.name
form_field_value = await part.text() # Read the value as text
form_data[form_field_name] = form_field_value
return uploaded_files, form_data

async def delete_uploaded_files(self, file_paths: list):
"""delete_uploaded_files.
Expand Down

0 comments on commit 4d64727

Please sign in to comment.