download a file

Discussion in 'Ruby' started by Fredy, Jun 4, 2008.

  1. Fredy

    Fredy Guest

    Hello
    I have a file on the server and i want it to be downloadable by users
    when they press on a link. i tried send_date, but it created a new
    file instead of grabbing the existing one.
    Here is the code

    def download
    send_data( path=>"public/files/test.doc" , :filename => "test.doc",
    :type => "text/doc", :disposition => "attachment")
    end

    any help will be appreciated :)
    Thank you
    Fred
    Fredy, Jun 4, 2008
    #1
    1. Advertising

  2. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Fredy wrote:
    | Hello
    | I have a file on the server and i want it to be downloadable by users
    | when they press on a link. i tried send_date, but it created a new
    | file instead of grabbing the existing one.
    | Here is the code
    |
    | def download
    | send_data( path=>"public/files/test.doc" , :filename => "test.doc",
    | :type => "text/doc", :disposition => "attachment")
    | end
    |
    | any help will be appreciated :)

    Is this Rails, Merb, or...?

    Anyway, if it is a framework, you might be better off asking the
    community around the framework for hints and help. ;)

    Anyway, if you are using Rails you could use link_to, for example, as
    described here:

    http://wiki.rubyonrails.org/rails/pages/HowToLinkToStaticFile

    Note: The code presented there could be vulnerable to code injection, so
    proceed with caution.

    - --
    Phillip Gawlowski
    Twitter: twitter.com/cynicalryan
    Blog: http://justarubyist.blogspot.com

    ~ Verbing weirds language.
    ~ --- Calvin.
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.8 (MingW32)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iEYEARECAAYFAkhG0IMACgkQbtAgaoJTgL/sxgCcDgq2BZj2c7p1cvT1nIBb+g0n
    EH0AnRtOJkQ+ac50aLeXgcrUyEIFeZyI
    =RAc7
    -----END PGP SIGNATURE-----
    Phillip Gawlowski, Jun 4, 2008
    #2
    1. Advertising

  3. Fredy

    Fredy Guest

    On Jun 4, 1:26 pm, Phillip Gawlowski <>
    wrote:
    > -----BEGIN PGP SIGNED MESSAGE-----
    > Hash: SHA1
    >
    > Fredy wrote:
    >
    > | Hello
    > | I have a file on the server and i want it to be downloadable by users
    > | when they press on a link. i tried send_date, but it created a new
    > | file instead of grabbing the existing one.
    > | Here is the code
    > |
    > | def download
    > | send_data( path=>"public/files/test.doc" , :filename => "test.doc",
    > | :type => "text/doc", :disposition => "attachment")
    > | end
    > |
    > | any help will be appreciated :)
    >
    > Is this Rails, Merb, or...?
    >
    > Anyway, if it is a framework, you might be better off asking the
    > community around the framework for hints and help. ;)
    >
    > Anyway, if you are using Rails you could use link_to, for example, as
    > described here:
    >
    > http://wiki.rubyonrails.org/rails/pages/HowToLinkToStaticFile
    >
    > Note: The code presented there could be vulnerable to code injection, so
    > proceed with caution.
    >
    > - --
    > Phillip Gawlowski
    > Twitter: twitter.com/cynicalryan
    > Blog:http://justarubyist.blogspot.com
    >
    > ~ Verbing weirds language.
    > ~ --- Calvin.
    > -----BEGIN PGP SIGNATURE-----
    > Version: GnuPG v1.4.8 (MingW32)
    > Comment: Using GnuPG with Mozilla -http://enigmail.mozdev.org
    >
    > iEYEARECAAYFAkhG0IMACgkQbtAgaoJTgL/sxgCcDgq2BZj2c7p1cvT1nIBb+g0n
    > EH0AnRtOJkQ+ac50aLeXgcrUyEIFeZyI
    > =RAc7
    > -----END PGP SIGNATURE-----


    Hello
    It's Rails :)
    here is the view code:
    <%= link_to "Download", { :action => "download" } , :post => true
    %>

    as i said in my previous thread, the file is already in the server; no
    need to create, just download it. but i got a new file created
    instead, with nothing in it.
    Thank youg
    Fredy, Jun 4, 2008
    #3
  4. -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Fredy wrote:

    | as i said in my previous thread, the file is already in the server; no
    | need to create, just download it. but i got a new file created
    | instead, with nothing in it.

    Have you looked at the link I mentioned? It solves the exact problem you
    have.

    - --
    Phillip Gawlowski
    Twitter: twitter.com/cynicalryan
    Blog: http://justarubyist.blogspot.com

    ZOOT: I'm afraid our life must seem very dull and quiet compared to
    yours. We are but eightscore young blondes, all between sixteen and
    nineteen-and-a-half, cut off in this castle, with no one to protect us.
    Oooh. It is a lonely life ... bathing ... dressing ... undressing ...
    making exciting underwear....
    ~ -- Monty Python and the Holy Grail
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.8 (MingW32)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

    iEYEARECAAYFAkhG1ncACgkQbtAgaoJTgL/6GgCcD6rNXP8h0E2Gqhcd66QJWCao
    YIAAoIuypce67MAfvwIzYjc7szqiUR9V
    =sQxe
    -----END PGP SIGNATURE-----
    Phillip Gawlowski, Jun 4, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Taylor
    Replies:
    2
    Views:
    922
    Ryan Taylor
    Nov 10, 2004
  2. Steve C. Orr [MVP, MCSD]
    Replies:
    0
    Views:
    1,588
    Steve C. Orr [MVP, MCSD]
    Mar 7, 2005
  3. Sam --
    Replies:
    2
    Views:
    594
    Sam --
    Mar 17, 2005
  4. Rafal Majda
    Replies:
    5
    Views:
    2,232
    Rafal Majda
    Apr 18, 2005
  5. Brett  Kelly
    Replies:
    1
    Views:
    663
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
Loading...

Share This Page