<#1893 feat: add file type validation and mime typ...
# flyte-github
a
#1893 feat: add file type validation and mime type extraction Pull request opened by jasonlai1218 TL;DR add file type validation and mime type extraction Type ☑︎ Bug Fix ☐ Feature ☐ Plugin Are all requirements met? ☑︎ Code completed ☐ Smoke tested ☑︎ Unit tests added ☐ Code documentation added ☐ Any pending items have an associated Issue Complete description • Import the
magic
module in
flytekit/types/file/file.py
• Add a method
get_mime_type_from_python_type
in
FlyteFilePathTransformer
class in
flytekit/types/file/file.py
• Add a validation for file type in
FlyteFilePathTransformer.to_literal
method in
flytekit/types/file/file.py
• Modify
setup.py
to include
python-magic>=0.4.27
as a dependency • Add a test case
test_real_file_type_in_workflow
in
test_flyte_file.py
Screenshot Local Test (Scenario: actual file type does not match the expected file type)

Screenshot 2023-10-15 at 11 34 13 PM▾

(Scenario: actual file type matches the expected file type)

Screenshot 2023-10-15 at 11 35 05 PM▾

(Scenario: actual pdf file type does match the expected pdf file type)

Screenshot 2023-10-15 at 11 33 01 PM▾

* * * Remote Test
docker build . -f Dockerfile.dev -t localhost:30000/flytekit:dev1 --build-arg PYTHON_VERSION=3.9
docker push localhost:30000/flytekit:dev1
pyflyte run --remote --image localhost:30000/flytekit:dev1 jpg_png_mismatch.py wf
(Scenario: actual file type does not match the expected file type)

Screenshot 2023-10-17 at 9 50 37 AM▾

Tracking Issue Fixes flyteorg/flyte#3834 Follow-up issue NA flyteorg/flytekit