From 1ec89b5f6a445aaa86854356cb73deb7e070d346 Mon Sep 17 00:00:00 2001 From: Nikita Manovich <40690625+nmanovic@users.noreply.github.com> Date: Wed, 25 Sep 2019 17:36:23 +0300 Subject: [PATCH] Selecting non images leads to 400 error (#734) * 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. --- cvat/apps/engine/media_extractors.py | 4 +++- cvat/apps/engine/task.py | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cvat/apps/engine/media_extractors.py b/cvat/apps/engine/media_extractors.py index 89a12bab..018671e1 100644 --- a/cvat/apps/engine/media_extractors.py +++ b/cvat/apps/engine/media_extractors.py @@ -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) diff --git a/cvat/apps/engine/task.py b/cvat/apps/engine/task.py index 7d1fbd18..f29a3135 100644 --- a/cvat/apps/engine/task.py +++ b/cvat/apps/engine/task.py @@ -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() }