Giter Club home page Giter Club logo

Comments (4)

t56k avatar t56k commented on August 29, 2024

This happens to me too. I lost the custom filename as a quick fix, but obvs that's not ideal.

from arc_ecto.

davidkuhta avatar davidkuhta commented on August 29, 2024

@joshuaswilcox
Try:

def filename(version, {file, _scope}), do: "#{version}_#{Path.basename(file.file_name, Path.extname(file.file_name))}"

See:
Arc Local Tests

from arc_ecto.

stavro avatar stavro commented on August 29, 2024

Ah - Thanks @davidkuhta.

As I currently have it, the "filename" should not include the extension, because different versions of a file may have different extensions. (i.e. you may want the original jpg file stored, but a thumbnail png).

If you have any suggestions on how to make that more clear I'm all 👂

from arc_ecto.

davidkuhta avatar davidkuhta commented on August 29, 2024

Hi @stavro
If I trace the code right I think this is actually more of an Arc consideration.
I believe the confusion stems from some examples in the Arc docs, that don't necessarily allude when you override the filename/2 function in storage.ex, you lose the default extension stripping:
def filename(_, {file, _}), do: Path.basename(file.file_name, Path.extname(file.file_name))

Particularly Local Configuration and File Names that show:
def filename(version, {file, scope}), do: "#{version}-#{file.file_name}"

So my thought would be to either:

  1. Provide a comment in the Arc docs that communicates file_name != basename (and includes Path.basename(file.file_name, Path.extname(file.file_name)))
  2. (My preference) Expose a helper function (say filename/1 in Arc.Definition.Storage) that strips the extension (ultimately what the default filename/2 was doing).
    So in storage.ex you'd now have:
def filename(_, {file, _}), do: filename(file)
def filename(file), do: Path.basename(file.file_name, Path.extname(file.file_name))

Option 2. would mean you could do things like:
def filename(version, {file, _scope}), do: "#{version}_#{filename(file)}"
It also wouldn't break anything because the filename/2 still provides the same implementation as it did before.

Note: I chose filename because basename/1 is used by Path but there's nothing to say it couldn't just be that. (Which IMHO is what I would've assumed Path.basename/1 did...) (stemname/1 was another thought)

Anyhow, let me know if either fits your vision for arc/arc_ecto and I'll be happy to send over a PR.

from arc_ecto.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.