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

Seperate store_filename from url_filename in definition #291

Open
coop opened this issue Oct 29, 2019 · 2 comments
Open

Seperate store_filename from url_filename in definition #291

coop opened this issue Oct 29, 2019 · 2 comments

Comments

@coop
Copy link

coop commented Oct 29, 2019

The documentation states that it's possible to change the filename with the filename function:

It may be undesirable to retain original filenames (eg, it may contain personally identifiable information, vulgarity, vulnerabilities with Unicode characters, etc).

You may specify the destination filename for uploaded versions through your definition module.

For our use case we want to replace the uploaded filename with something randomly generated (not derived from the original filename). I have noticed that that the filename function is used to both generate new filenames and create publicly accessible urls... From what I can see this is problematic when the filename function contains data that is not derivable from the original filename. For example this is the implementation of our filename function:

defmodule MyDefinition do
  def filename(_version, {_file, _scope}) do
    now = DateTime.to_unix(DateTime.utc_now(), :millisecond)
    token = 16 |> :crypto.strong_rand_bytes() |> Base.url_encode64()

    "#{now}_#{token}"
  end
end

This correctly creates a filename with now + token but when I ask for the url I get something completely random because it invokes filename again.

Am I doing this correctly? Is there a different API I should be using? Have I misunderstood the documentation?

I am using ecto-arc so I know the correct filename - I am thinking of reimplementing this functionality by only calling filename when storing the image and passing through for url or separating store_filename vs url_filename.

It's possible that this functionality already exists and I'm just missing it somewhere.

Thanks

@achempion
Copy link

You can check if the scope already has the defined filename and use the old instead of generating new one.

@coop
Copy link
Author

coop commented Feb 24, 2020

@achempion do you have an example of how to do that?

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

2 participants