Forum: Ruby on Rails File I/O with rjb

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Martin S. (Guest)
on 2007-03-05 23:34
(Received via mailing list)
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
This topic is locked and can not be replied to.