我有一个带有文件字段的HTML表单,用于将文件上传到我的Phoenix应用程序中的/file
路径。
我使用curl -v -F "file=@MyTestFile" http://localhost:4000/file/
从命令行模仿此行为,以加快测试速度。
当我使用大文件(转折点似乎大约为7.7MB)时,我从Plug获得以下异常:
18:40:38.897 [错误]过程中的错误< 0.420.0>具有退出值:{[{reason,#{' 例外' => true,' struct ' => ;' Elixir.Plug.Parsers.RequestTooLargeError',消息=>零}},{MFA,{' Elixir.Plug.Adapters.Cowboy.Handler'在初始化,3}} ,{stacktrace,[{' Elixir.Plug.Parsers',reduce,6,[{file," lib / plug ...
是否有解决方法允许上传更大的文件?
Plug中似乎有一个:length
选项关键字,但我如何从Phoenix设置它?那个8_000_000
的特定价值被选中的原因是什么?
答案 0 :(得分:6)
您可以在config/config.exs
文件中配置:
config :phoenix, MyApp.Router,
...
parsers: [parsers: [:urlencoded, :multipart, :json],
accept: ["*/*"],
json_decoder: Poison,
length: 100_000_000],
答案 1 :(得分:0)
仅供参考,有关此功能的最新文档(由于此问题和这些答案在此时已过时),请参阅官方文档:https://phoenixframework.org/blog/file-uploads