# POST'ing a file with link\_to

**URL:** <https://www.ruby-forum.com/t/posting-a-file-with-link-to/146773>\
**Category:** Rails\
**Created:** [August 25, 2008, 11:55am UTC](https://www.ruby-forum.com/t/posting-a-file-with-link-to/146773 "2008-08-25T11:55:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [August 25, 2008, 11:55am UTC](https://www.ruby-forum.com/t/posting-a-file-with-link-to/146773/1 "2008-08-25T11:55:00Z")

</div>

Dear all,

For a site I need a demo functionality. Long story short, I need  
people to be able to click a link which POST’s a file (which I, in  
this instance, provide).

So far I’ve got:  
\<%= link\_to(“Example”, new\_resource\_path(:uploaded\_data =\> “files/  
some.pdf”), :method =\> :post, :multipart =\> true) %\>  
Obviously this does not work as the :uploaded\_data param contains a  
string and not the file. But I am at a loss on how to fix this.  
Any help is greatly appreciated.

With kind regards,

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [August 25, 2008, 12:45pm UTC](https://www.ruby-forum.com/t/posting-a-file-with-link-to/146773/2 "2008-08-25T12:45:23Z")

</div>

Don’t know if you can use path helpers for that, but:

link\_to(“Example”, “/docs/gebruikersovereenkomst.pdf”)

would work if the pdf is in the /docs folder below RAILS\_ROOT

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [August 25, 2008, 12:58pm UTC](https://www.ruby-forum.com/t/posting-a-file-with-link-to/146773/3 "2008-08-25T12:58:51Z")

</div>

Unfortunately I was a bit unclear in my initial post. What I want is  
to POST a file to a controller. So the user never sees the file. In  
effect I want to simulate a form with a file field, but with the file  
field already filled out.

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [August 25, 2008, 1:22pm UTC](https://www.ruby-forum.com/t/posting-a-file-with-link-to/146773/4 "2008-08-25T13:22:54Z")

</div>

hi,  
you could make a helper that writes a form something like that:

Your text

but you should know that you can’t upload a file that hasn’t been  
previously selected through a file input due to security reasons. you  
could do this only when client and server are on the same machine…

regards

harm escribiÃ³:

> > would work if the pdf is in the /docs folder below RAILS\_ROOT

/\*\*

- dagi3d v4 - [http://dagi3d.net](http://dagi3d.net)  
\*/

---

<div class="post-metadata">

**Author:** ![harm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/b4bc9f/32.png) [@harm](https://www.ruby-forum.com/u/harm)\
**Post date:** [August 25, 2008, 1:49pm UTC](https://www.ruby-forum.com/t/posting-a-file-with-link-to/146773/5 "2008-08-25T13:49:18Z")

</div>

I was unaware of that fact. Hmmm. Makes a lot of sense though.  
Thanks for your suggestion!
