# Ruby (rails) and rjb: java File I/O

**URL:** <https://www.ruby-forum.com/t/ruby-rails-and-rjb-java-file-i-o/87784>\
**Category:** Ruby\
**Created:** [March 5, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/ruby-rails-and-rjb-java-file-i-o/87784 "2007-03-05T23:16:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![msojka](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b5a626/32.png) [@msojka](https://www.ruby-forum.com/u/msojka)\
**Post date:** [March 5, 2007, 11:16pm UTC](https://www.ruby-forum.com/t/ruby-rails-and-rjb-java-file-i-o/87784/1 "2007-03-05T23:16:08Z")

</div>

I am trying to do file i/o with rails and rjb and can’t figure out a  
way to make this work.

Here’s what I am trying to do:

- a user uploads an image to the server via a standard html form:  
\<%= file\_field(“blog”, “attach”) %\>
- this returns a ruby File object to the controller in  
params[:blog][:attach]
- then I need to convert this into a Java InputStream object in order  
to use it as an argument to another Java method.

I have tried to accomplish this many ways by using the obvious  
approach … all without success.  
For example,

- read the contents of the file into a ruby string, then try to create  
a java ByteArrayInputStream directly from this.
- read the contents of the file into a ruby string, create a java  
String from this and then try to create a java ByteArrayInputStream  
from the java String
- and many other permutations  
I fear I am missing something very simple here…

Has anyone accomplished something like this? If so I would appreciate  
seeing a sample of actual working code.

Thanks,  
Martin
