# Request.raw\_post data saving for image getting error

**URL:** <https://www.ruby-forum.com/t/request-raw-post-data-saving-for-image-getting-error/193278>\
**Category:** Rails\
**Created:** [August 14, 2010, 5:12pm UTC](https://www.ruby-forum.com/t/request-raw-post-data-saving-for-image-getting-error/193278 "2010-08-14T17:12:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yogendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@yogendra](https://www.ruby-forum.com/u/yogendra)\
**Post date:** [August 14, 2010, 5:12pm UTC](https://www.ruby-forum.com/t/request-raw-post-data-saving-for-image-getting-error/193278/1 "2010-08-14T17:12:44Z")

</div>

Hi,

I am try to saving the request.raw\_post in file and try to saving image  
as regular paperclip saving image… i m getting the error  
‘Errno::EBADF (Bad file descriptor):’

can anybody tell me how sorted out this.

Thanks in advance

---

<div class="post-metadata">

**Author:** ![yogendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@yogendra](https://www.ruby-forum.com/u/yogendra)\
**Post date:** [August 14, 2010, 6:47pm UTC](https://www.ruby-forum.com/t/request-raw-post-data-saving-for-image-getting-error/193278/2 "2010-08-14T18:47:22Z")

</div>

On 14 August 2010 16:12, Yogendra S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am try to saving the request.raw\_post in file and try to saving image  
> as regular paperclip saving image… i m getting the error  
> ‘Errno::EBADF (Bad file descriptor):’
> 
> can anybody tell me how sorted out this.

Please show us your controller code, and the code around where the  
EBADF exception was raised.

As a wild guess, it sounds like you’re trying to pass request.raw\_post  
directly into Paperclip, while Paperclip is expecting to get a TmpFile  
or StringIO object (as it would it you just passed the parameter  
containing the file).

Chris

---

<div class="post-metadata">

**Author:** ![yogendra](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/c89c15/32.png) [@yogendra](https://www.ruby-forum.com/u/yogendra)\
**Post date:** [August 14, 2010, 6:51pm UTC](https://www.ruby-forum.com/t/request-raw-post-data-saving-for-image-getting-error/193278/3 "2010-08-14T18:51:35Z")

</div>

Chris M. wrote:

> On 14 August 2010 16:12, Yogendra S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > ï¿½I am try to saving the request.raw\_post in file and try to saving image  
> > as regular paperclip saving image… i m getting ï¿½the error  
> > ‘Errno::EBADF (Bad file descriptor):’
> > 
> > ï¿½can anybody tell me how sorted out this.
> 
> Please show us your controller code, and the code around where the  
> EBADF exception was raised.
> 
> As a wild guess, it sounds like you’re trying to pass request.raw\_post  
> directly into Paperclip, while Paperclip is expecting to get a TmpFile  
> or StringIO object (as it would it you just passed the parameter  
> containing the file).
> 
> Chris  
> here are my controller code

" name = “tmp\_image.png”  
data = request.raw\_post  
@file\_content = File.open(“#{RAILS\_ROOT}/tmp/#{name}”, “wb”) { |f|  
f.write(data) } if data  
@photo = Picture.new(:image =\> File.new(@file\_content))  
@photo.save "
