I'm trying to upload images to my Phoenix app on Heroku. I have a simple app that follows the instructions for file uploading from Phoenix's docs.
I have a simple form and the controller uses File.cp_r()
to copy the file from the temp directory.
def create(conn, %{"user" => user_params}) do
if upload = user_params["photo"] do
File.cp_r(upload.path, "priv/static/images/foo.jpg") #non-dynamic name, doens't matter
end
...
end
Works just file on my local. However when I upload this to Heroku, test the form and heroku run find
on the directory, I don't see anything.
I have noticed that this directory on heroku has a seemingly forbidding privilege:
drwx------ 2 u25619 dyno 4096 Apr 23 05:14 images
I tried slipping in a nice little File.chmod("priv/static/images", 0o777)
, but to no avail; that directory seems locked away from me, so I think this is a heroku issue.
Any idea how to handle this?
EDIT: Resolved by using the phoenix dep ex_aws
to upload to an Amazon S3 bucket.
- ex_aws dependency
- partial explanation (note: you need to add poison and hackney to make this work, they are not mentioned)