Giter Site home page Giter Site logo

Comments (2)

dvdplm avatar dvdplm commented on July 19, 2024

We are experiencing the same issue and it's going to be something of a showstopper for us. Given a valid uid, say "avatar/123/big_original.jpg", how can I generate the url for it in javascript? As it stands, Dragonfly base64 encodes it AND Marshals it, so any other language is cut out.

I've been wondering about the reason for this implementation choice but come up short. There's not much extra data in there:

>> Base64.decode64("BAhbBlsHOgZmSSIaaW1hZ2VzLzEvb3JpZ2luYWwuanBnBjoGRVQ.jpg")
=> "\x04\b[\x06[\a:\x06fI\"\x1Aimages/1/original.jpg\x06:\x06ET#"
>> Marshal.load _
=> [[:f, "images/1/original.jpg"]]

Surely it can't be a security measure?

from dragonfly.

markevans avatar markevans commented on July 19, 2024

It's not a security measure, but it is quicker, easier and more flexible than json encoding it, as well as not relying on any other library.
It easily allows for complex multi-step jobs with option hashes as arguments. It just happens that this the most simple example of a job.

I created routed endpoints for exactly the type of thing you're doing: http://markevans.github.com/dragonfly/file.URLs.html#Routed_Endpoints

If you're using Rails 3, you could create a simple routed endpoint, e.g.:

match '/images/:uid' => Dragonfly[:images].endpoint{|params, app|
  app.fetch(params[:uid])
}

Then creating the route in javascript is as simple as

'/images/' + encodeURIComponent(uid)

encodeURIComponent(uid) is needed because forward slashes will confuse the rails routing system.

You could even use sizes, etc.:

match '/images/:uid/:size' => Dragonfly[:images].endpoint{|params, app|
  app.fetch(params[:uid]).thumb(params[:size])
}

from dragonfly.

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.