LoginSignup
0
0

More than 3 years have passed since last update.

AWS Lambdaでmimetypesを使う際はtypes_mapを確認しよう(Python)

Posted at

前提・環境

AWS Lambda Python環境

事象

AWS LambdaのPython環境で.webpguess_typeしようとしたところ。

import mimetypes
print(mimetypes.guess_type('.webp'))
# none

noneになってしまった。

import mimetypes
print(mimetypes.types_map['.webp'])
# none

types_mapにwebpが存在しないので、追加してあげて

import mimetypes
mimetypes.add_type('image/webp', '.webp')
print(mimetypes.guess_type('.webp'))
# image/webp

解決した。

まとめ

mimetypesの辞書は環境依存なので、guess_typeguess_extentionできないときは辞書に対象が存在するか確認する。
存在しない場合はadd_typeで追加することができる。

参考)https://note.nkmk.me/python-mimetypes-usage/

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0