Skip to content

Commit

Permalink
Selecting non images leads to 400 error (cvat-ai#734)
Browse files Browse the repository at this point in the history
* Fix HTTP 400 error if together with vision data the user submit non-vision data (e.g. text files)
* Ignore SVG images because Pillow doesn't work with them.
  • Loading branch information
nmanovic authored and Chris Lee-Messer committed Mar 5, 2020
1 parent 2e2ff55 commit ce9de8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion cvat/apps/engine/media_extractors.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,9 @@ def _is_video(path):

def _is_image(path):
mime = mimetypes.guess_type(path)
return mime[0] is not None and mime[0].startswith('image')
# Exclude vector graphic images because Pillow cannot work with them
return mime[0] is not None and mime[0].startswith('image') and \
not mime[0].startswith('image/svg')

def _is_dir(path):
return os.path.isdir(path)
Expand Down
7 changes: 6 additions & 1 deletion cvat/apps/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,12 @@ def _validate_data(data):
def count_files(file_mapping, counter):
for rel_path, full_path in file_mapping.items():
mime = get_mime(full_path)
counter[mime].append(rel_path)
if mime in counter:
counter[mime].append(rel_path)
else:
slogger.glob.warn("Skip '{}' file (its mime type doesn't "
"correspond to a video or an image file)".format(full_path))


counter = { media_type: [] for media_type in MEDIA_TYPES.keys() }

Expand Down

0 comments on commit ce9de8a

Please sign in to comment.