Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
5ef0951d
Unverified
Commit
5ef0951d
authored
7 years ago
by
Justin Ehlert
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1078 from scitran/packfile-multi-value
Fix handling of multi-value file fields
parents
58866be2
1a21390b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/upload.py
+16
-4
16 additions, 4 deletions
api/upload.py
tests/integration_tests/python/test_uploads.py
+6
-1
6 additions, 1 deletion
tests/integration_tests/python/test_uploads.py
with
22 additions
and
5 deletions
api/upload.py
+
16
−
4
View file @
5ef0951d
...
...
@@ -91,16 +91,13 @@ def process_upload(request, strategy, container_type=None, id_=None, origin=None
# Here, we accept any
# Non-file form fields may have an empty string as filename, check for 'falsy' values
file_fields
=
[
x
for
x
in
form
if
form
[
x
].
filename
]
file_fields
=
extract_file_fields
(
form
)
# TODO: Change schemas to enabled targeted uploads of more than one file.
# Ref docs from placer.TargetedPlacer for details.
if
strategy
==
Strategy
.
targeted
and
len
(
file_fields
)
>
1
:
raise
FileFormException
(
"
Targeted uploads can only send one file
"
)
for
field
in
file_fields
:
field
=
form
[
field
]
# Augment the cgi.FieldStorage with a variety of custom fields.
# Not the best practice. Open to improvements.
# These are presumbed to be required by every function later called with field as a parameter.
...
...
@@ -270,3 +267,18 @@ class Upload(base.RequestHandler):
'
directories
'
:
cleaned
,
}
}
def
extract_file_fields
(
form
):
"""
Returns a list of file fields in the form, handling multiple values
"""
result
=
[]
for
fieldname
in
form
:
field
=
form
[
fieldname
]
if
isinstance
(
field
,
list
):
for
field_entry
in
field
:
if
field_entry
.
filename
:
result
.
append
(
field_entry
)
elif
field
.
filename
:
result
.
append
(
field
)
return
result
This diff is collapsed.
Click to expand it.
tests/integration_tests/python/test_uploads.py
+
6
−
1
View file @
5ef0951d
...
...
@@ -1197,9 +1197,14 @@ def test_packfile_upload(data_builder, file_form, as_admin, as_root, api_db):
assert
r
.
ok
token
=
r
.
json
()[
'
token
'
]
files
=
[
(
'
file
'
,
file_form
(
'
two.csv
'
)[
'
file
'
])
,
(
'
file
'
,
file_form
(
'
three.csv
'
)[
'
file
'
])
]
# upload to packfile
r
=
as_admin
.
post
(
'
/projects/
'
+
project
+
'
/packfile
'
,
params
=
{
'
token
'
:
token
},
files
=
file
_form
(
'
two.csv
'
)
)
params
=
{
'
token
'
:
token
},
files
=
file
s
)
assert
r
.
ok
# expire upload token
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment