# Tempfile, StringIO, and TestUploadedFile

**URL:** <https://www.ruby-forum.com/t/tempfile-stringio-and-testuploadedfile/79225>\
**Category:** Rails\
**Created:** [December 13, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/tempfile-stringio-and-testuploadedfile/79225 "2006-12-13T13:36:13Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ry\_Dahl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/f14d63/32.png) [@Ry\_Dahl](https://www.ruby-forum.com/u/Ry_Dahl)\
**Post date:** [December 13, 2006, 1:36pm UTC](https://www.ruby-forum.com/t/tempfile-stringio-and-testuploadedfile/79225/1 "2006-12-13T13:36:13Z")

</div>

When a multipart post is sent to Rails, the framework creates a  
“modified Tempfile” which is a Tempfile object but with two extra  
methods: content\_type and original\_filename (sometimes if the file  
being upload is small enough Rails will give you a modified StringIO  
class).

Helpfully the framework provides ActionController::TestUploadedFile to  
allow users to mimic this behavior in unit tests.

I’m finding myself hacking around Rail’s behavior - trying to pass  
uploaded files to my models requires type checks: one action for  
Tempfile, one for StringIO, and for testing one for TestUploadedFile.  
Of course, I could just be passing the raw data to my file; but I  
don’t want to fill up my RAM.

Why this design? Why not simply an ActionController::UploadedFile?

Thanks,  
Ryan Dahl

ps I’m having some problems with google groups - hopefully I haven’t  
sent this message multiple times to the list. If so, sorry.
