File uploads via web service

I need to write a web service that accepts file uploads (even large
ones). My WS is REST based, so I have a create method that accepts
only POST.
My problem is passing the file to the method, so if someone already
solved this problem please let me know.
For example, do I need to use Base64 encoding, and decode inside ?
My method is like this:

def create
radio = Radio.create!( params[ :radio ] )
ad = Ad.new( params[ :ad ].merge( :user => current_user, :resource
=> radio ) )
ad.save!
respond_to do |format|
format.html
format.xml { render :xml => ad.to_xml, :status => :created }
end
rescue ActiveRecord::RecordInvalid
respond_to do |format|
format.html { render :action => :new }
format.xml { render :xml => " #{e.message} </
error> ", :status => :unprocessable_entity }
end
end

My concern is about what gets saved inside the Radio object, I don’t
think I can pass a raw binary object (AFAIK).
Also, about rspeccing the whole thing, I think I need to write
controller tests that check that the file I begin with is exactly the
same I have after using the WS, but isn’t it something I shouldn’t do
in RSpec ? I mean, using real data. In this case I can have the
controller behaving exactly as I think it should by calling the right
methods in the right way, but having a corrupted file in the fs … I
can’t test data in the model either, because corruption will happen
exactly inside the controller.
I’m new to this stuff, so I’m pretty clueless. Every help is very
appreciated.

TIA,
ngw

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs