本文介绍了在生产模式下以Phoenix读取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Phoenix应用程序(我使用--api标志创建了它),其中包含一些处理我存储在priv/data/filters.csv中的请求所需的其他数据.

I've Phoenix app (I created it with --api flag) that has some additional data required to process requests that I store in priv/data/filters.csv.

因此它在dev模式下可以正常工作,我可以像这样读取该文件:File.stream!("priv/data/filters.csv"),但是一旦使用mix edeliver update交付应用后,该文件将无法再访问.

So it works fine in dev mode, I can read this file like: File.stream!("priv/data/filters.csv"), but once app is delivered using mix edeliver update this file is not accessible anymore.

我可以在构建目录中看到此文件夹,但是在交付应用程序之后,没有这样的文件夹priv.我不确定为什么不将其复制到传递文件夹中.

I can see this folder in build directory, but after app is delivered there is no such folder priv. I'm not sure why it's not copied to deliver folder.

我做错了什么?交付过程后是否需要复制这些文件?在哪里可以存储必须以生产方式使用的文件?

What I'm doing wrong? Do I need to copy these files after deliver process?Where can I store my files that I have to use in prod mode?

推荐答案

您应使用:code.priv_dir/1在运行时获取应用程序priv目录的绝对路径.这将适用于由例如创建的Erlang版本.酒厂:

You should use :code.priv_dir/1 to get the absolute path to the priv directory of your application at runtime. This will work with Erlang releases created by e.g. Distillery:

File.stream!(Path.join(:code.priv_dir(:my_app), "data/filters.csv"))

对我来说,执行MIX_ENV=prod mix release后,文件priv/foo被复制到_build/prod/lib/my_app/priv/foo.

For me, after doing MIX_ENV=prod mix release, the file priv/foo is copied to _build/prod/lib/my_app/priv/foo.

这篇关于在生产模式下以Phoenix读取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 15:01