Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it posible to upload images from a remote url? #52

Open
jessiahr opened this issue Dec 14, 2016 · 3 comments
Open

Is it posible to upload images from a remote url? #52

jessiahr opened this issue Dec 14, 2016 · 3 comments

Comments

@jessiahr
Copy link

The Arc API docs show it being able to store an image from a web URL:

# Store any locally accessible file
Avatar.store("/path/to/my/file.png") #=> {:ok, "file.png"}

# Store any remotely accessible file
Avatar.store("http://example.com/image.png") #=> {:ok, "file.png"}

Is that posible with arc_ecto and if so could you give an example?

@Iwark
Copy link

Iwark commented Dec 30, 2016

You can:

|> cast_attachements(params, [:image], allow_paths: true)

Changelog

@denispeplin
Copy link

denispeplin commented Aug 11, 2017

This leads to security issue: I want only allow to upload files from remote URL, but this also allows local uploads (any file from /etc for example).
Can I disallow local uploads, but with remote uploads still enabled?
Or should I implement some custom validation to prevent local uploads?

@jung-hunsoo
Copy link

jung-hunsoo commented Dec 26, 2017

@denispeplin How about adding a custom validation which filters only valid URLs like starting with http or https?

Personally, I'm using a filter like this;

  defp apply_image_remote_url(attrs) do
    case attrs["image_remote_url"] != nil && String.starts_with?(attrs["image_remote_url"], ["http://", "https://"]) do
      true -> Map.put(attrs, "image", attrs["image_remote_url"])
      false -> attrs
    end
  end

I think it'd better to provide options in addition to allow_paths in the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants