# File uploads via web service

**URL:** <https://www.ruby-forum.com/t/file-uploads-via-web-service/143146>\
**Category:** Rails\
**Created:** [July 15, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/file-uploads-via-web-service/143146 "2008-07-15T18:01:33Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [July 15, 2008, 6:01pm UTC](https://www.ruby-forum.com/t/file-uploads-via-web-service/143146/1 "2008-07-15T18:01:33Z")

</div>

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
