# Name = upload\['datafile'\].original\_filename

**URL:** <https://www.ruby-forum.com/t/name-upload-datafile-original-filename/195244>\
**Category:** Ruby\
**Created:** [September 20, 2010, 2:02pm UTC](https://www.ruby-forum.com/t/name-upload-datafile-original-filename/195244 "2010-09-20T14:02:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 20, 2010, 2:02pm UTC](https://www.ruby-forum.com/t/name-upload-datafile-original-filename/195244/1 "2010-09-20T14:02:37Z")

</div>

At: [Ruby on Rails - File Uploading | Tutorialspoint](http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm)

And, regarding:

name = upload[‘datafile’].original\_filename

It mentions that “upload” is a CGI object.

If you look at the header of the function this line is part of:

def self.save(upload)

It seems that there is an argument “upload”.

But, in the body, when we say:

upload[‘datafile’]

Is “upload” here the same as the passed argument?

And, what about [‘datafile’], what does it represent here? And, from  
where is it passed?

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 20, 2010, 2:41pm UTC](https://www.ruby-forum.com/t/name-upload-datafile-original-filename/195244/2 "2010-09-20T14:41:57Z")

</div>

Thanks a lot @Brian for this nice clarification.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 20, 2010, 2:34pm UTC](https://www.ruby-forum.com/t/name-upload-datafile-original-filename/195244/3 "2010-09-20T14:34:55Z")

</div>

Abder-Rahman A. wrote:

> Is “upload” here the same as the passed argument?

Yes. Just to be clear, the code here is:

def self.save(upload)  
name = upload[‘datafile’].original\_filename

> And, what about [‘datafile’], what does it represent here?

It’s a method call on the object passed as upload. You are calling the  
method called ‘[]’, and passing the string ‘datafile’ as the argument.

What this actually does, depends on what the object ‘upload’ is. All you  
can tell from the above is that it implements a method called [] which  
takes a string argument. It could be a Hash, for example, in which case  
upload[‘datafile’] would retrieve the value keyed by ‘datafile’.

But it could be some other custom object. For example:

class Foo  
def   
puts “Called [] with key #{key.inspect}”  
“hello”  
end  
end

f = Foo.new  
result = f[“datafile”] # Called [] with key “datafile”  
puts result # hello

That’s the joy of duck-typing. You don’t care what class an object is,  
only what methods it responds to.
