# Upload file with url parameter

**URL:** <https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668>\
**Category:** Rails\
**Created:** [May 11, 2009, 10:29am UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668 "2009-05-11T10:29:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 11, 2009, 10:29am UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/1 "2009-05-11T10:29:29Z")

</div>

I want to upload file using get method.  
for example, “[http://www.mydomain.com/upload?file=c:\test.exe](http://www.mydomain.com/upload?file=c:%5Ctest.exe)” upload  
my local file to the remote server.  
I found one useful link about file uploading here(http://  
[Ruby on Rails - File Uploading | Tutorialspoint](http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm)).  
Even I’ve changed some code in order to fit my rails version, it  
worked well. But the problem is I have use tag.

I don’t know how [view] make UploadedFile and pass it to [controller]  
and I tried to find how create UploadedFile. But failed ☹

Anyway, how can I upload my local file using above style url?

help me plz, thx

---

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 11, 2009, 12:12pm UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/2 "2009-05-11T12:12:16Z")

</div>

I just want the client(kind a application running automatically) to  
upload file to the web server as it wants.

How do I do this?

On 5¿ù11ÀÏ, ¿ÀÈÄ5½Ã53ºÐ, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 11, 2009, 10:54am UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/3 "2009-05-11T10:54:10Z")

</div>

On May 11, 7:52 am, “[hongseok.com](http://hongseok.com)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Anyway, how can I upload my local file using above style url?

If you want to just pass the path of the file that won’t work - the  
file needs to be part of the request body. In theory get requests can  
have a request body, but certainly in browser land this isn’t common.  
it might just work if you set the form’s method to get (don’t forget  
to make the form multipart).  
Why is this important ?

Fred

---

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 11, 2009, 12:40pm UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/4 "2009-05-11T12:40:30Z")

</div>

On May 11, 11:11 am, “[hongseok.com](http://hongseok.com)” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I just want the client(kind a application running automatically) to  
> upload file to the web server as it wants.
> 
> How do I do this?

you’ll need to construct an appropriate post request (read up on  
multipart post requests) containing the file

Fred

---

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 12, 2009, 2:28pm UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/5 "2009-05-12T14:28:15Z")

</div>

This is exactly what I’ve been trying to do all day. Not as easy as  
you’d think. There are absolutely no examples of this available  
anywhere.

It’s a wonder that people haven’t been trying to do this for a while  
'cause it has many different uses, like streaming data directly  
through the 80 port when all other ports are blocked.

B

On May 11, 12:39 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 12, 2009, 10:04pm UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/6 "2009-05-12T22:04:53Z")

</div>

Unless either someone develops a wonderful (i use the term _very_  
loosely) exploit or I misunderstand what you’re trying to do here,  
there is no way to do what you’re trying to do. Neither Javascript,  
Flash, nor Java (unless the user’s insane and sets up their JVM to do  
this) can automatically read/serialize/change the value of a field to  
a local file. For very obvious security reasons, the only way to  
upload a file with a web browser is for the user to actively select  
the file they want, and then to send that in a POST request (GETs will  
not work as you cannot serialize the file data).

---

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 13, 2009, 9:46am UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/7 "2009-05-13T09:46:23Z")

</div>

Hi Bennet,

On 12 May 2009, at 13:07, PyroHiroshi wrote:

> This is exactly what I’ve been trying to do all day. Not as easy as  
> you’d think. There are absolutely no examples of this available  
> anywhere.

The mechanize gem makes file uploads a no-brainer…

Check out their example script which automates file uploads to Flickr  
in 10 or so lines of Ruby code:

```
 http://github.com/tenderlove/mechanize/blob/a5d73af1f7f4f8d6889b6da68899b9357a63b847/examples/flickr_upload.rb

```

Also check out the mechanize homepage for more examples and API  
documentation:

```
 http://mechanize.rubyforge.org/mechanize/

```

Mechanize FTW! 😉

Peter

---

<div class="post-metadata">

**Author:** ![hongseok.com](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/8c91f0/32.png) [@hongseok.com](https://www.ruby-forum.com/u/hongseok.com)\
**Post date:** [May 12, 2009, 10:21pm UTC](https://www.ruby-forum.com/t/upload-file-with-url-parameter/167668/8 "2009-05-12T22:21:54Z")

</div>

The only way to do anything like that would be to have the user install  
a client on their computer. For example, you can upload arbitrary files  
using adobe air. But otherwise, is verboten.

## SH

Starr H.  
Check out my Helpdesk RailsKit: [http://railskits.com/helpdesk/](http://railskits.com/helpdesk/)
