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.
main
Nikita Manovich 6 years ago committed by GitHub
parent 6cb05c8a8f
commit 1ec89b5f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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)

@ -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() }

Loading…
Cancel
Save