我在配置ARC以便在我的应用中工作时遇到问题。首先,当我使用如下所述的配置时,文件将加载到本地存储中。如果我添加行
def __storage, do: Arc.Storage.Local
到uploader.ex
,我收到了一个错误 - 没有太多信息:“出了问题。”此外,当我尝试直接上传时,会发生以下情况:
iex(2)> Avatar.store("/Users/carlson/Downloads/jupiter.jpg")
{:ok, "jupiter.jpg"}
然而,当我检查我的S3桶时,我发现只有几件旧物品。没有任何东西被添加到本地存储
CONFIG
config :arc,
storage: Arc.Storage.S3,
bucket: "noteimages"
config :ex_aws,
access_key_id: System.get_env("AWS_ACCESS_KEY_ID"),
secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY")
MIX.EXS
defp deps do
[{:phoenix, "~> 1.2.1"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:comeonin, "~> 2.0"},
{:mnemonix, "~> 0.2.0"},
{:timex, "~>3.0"},
{:timex_ecto, "~> 3.0"},
{:benchfella, "~> 0.3.2"},
{:json, "~> 1.0"},
{:joken, "~> 1.1"},
{:arc, "~> 0.8.0"},
{:arc_ecto, "~> 0.4", override: true},
{:shared, in_umbrella: true},
{:ex_aws, "~> 1.1"},
{:poison, "~> 2.0"},
{:httpoison, "~> 0.11"},
{:hackney, "~> 1.6"}]
end
S3 Bucket政策
{
"Version":"2012-10-17",
"Id":"Policy1493266128611",
"Statement":[
{
"Sid":"Stmt1493266101437",
"Effect":"Allow",
"Principal":{
"AWS":"*"
},
"Action":"s3:GetObject",
"Resource":"arn:aws:s3:::noteimages/*"
}
]
}
答案 0 :(得分:1)
您的问题可能是在配置中使用以下内容。
config :ex_aws,
access_key_id: System.get_env("AWS_ACCESS_KEY_ID"),
secret_access_key: System.get_env("AWS_SECRET_ACCESS_KEY")
您在编译时绑定环境变量,而不是运行时。如果您查看Arc Readme,您会看到配置的以下语法
{:system, "AWS_S3_BUCKET"}
所以,试试这个:
config :ex_aws,
access_key_id: {:system,"AWS_ACCESS_KEY_ID"},
secret_access_key: {:system, "AWS_SECRET_ACCESS_KEY"}
要仔细检查,请在iex中运行服务器并检查此配置
AWS_ACCESS_KEY_ID=... AWS_SECRET_ACCESS_KEY=... iex -S mix phx.server
iex> Application.get_env :ex_aws, :access_key_id
并确保它具有正确的值。