Thanks for the reply, Peter.  Unfortunately, this is not what is
happening in my application. Are you uploading images or passing
binary data created in Flash to Rails?

What is happening for us is that I am able to get the content-type as
"image/jpeg" using mimetype_fu, but that is as far as things go. If I
then try to save that data in the controller (using attachment_fu),
like so:

image_params = {:uploaded_data => params['image_uploaded_data']}
image = @visual_note.build_image(image_params.merge(:created_by =>
current_user))
if image.valid?
 #do stuff
else
 #errors
end

I get validates_as_attachment errors:
Content type can't be blank; Size can't be blank; Size is not included
in the list; Filename can't be blank

***

When I use some attachment_fu_hacks that I found here:
http://seventytwo.co.uk/posts/making-swfupload-and-rails-work-together:

  def uploaded_data=(file_data)
    return nil if file_data.nil? || file_data.size == 0
    self.content_type = detect_mimetype(file_data)
    self.filename     = file_data.original_filename if respond_to?
(:filename)
    if file_data.is_a?(StringIO)
      file_data.rewind
      self.temp_data = file_data.read
    else
      self.temp_path = file_data.path
    end
  end

  def detect_mimetype(file_data)
    if file_data.content_type.strip == "application/octet-stream"
      return File.mime_type?(file_data.original_filename)
    else
      return file_data.content_type
    end
  end
end

Errors are thrown because file_data -- the string passed in through my
params[:image_uploaded_data] from Flash does not respond to
content_type or original_filename

***

Am I missing something from the point where the I am receiving the
data in the controller and getting it to attachment_fu? It doesn't
know it is application/octet-stream because it doesn't respond to
content-type at the controller level.

Thanks,
Sarah



On Jan 15, 3:11 am, Peter De Berdt <peter.de.be...@pandora.be> wrote:
> On 15 Jan 2009, at 03:48, sarah wrote:
>
> > I'm working on a rails app with a flash application in it, and the
> > flash application posts binary data to the rails app, to create and
> > upload an image. The image arrives from Flash with a  Content-Type of
> > "application/octet-stream", but by the time the image data hits the
> > controller action, it is a string.
>
> That's merely because of the filesize of the data you are sending.  
> Everything below 16KB will be seen as StringIO, above it will be a  
> TempFile. Attachment_fu has everything in place to handle it.
>
> Look at line 303 
> athttp://github.com/technoweenie/attachment_fu/blob/743a95be0f01696530f...
>
> > I have googled and found numerous solutions for similar cases: getting
> > the content_type of data uploaded from flash (generally via swfobject)
> > and adjusting for when the content-type is application/octet-stream.
> > But, these don't work in my case -- I'm guessing that all those cases
> > are for actually uploading files rather than transporting binary
> > data.
>
> Attachment_fu combined with mimetype_fu work perfectly for me with any  
> data sent from Flash. Flash has no way to pass in the appropriate  
> content type (simply said: it's always application/octet-stream), but  
> I can see in your controller that you have a filename available  
> (xxxx.jpg). This should be enough for mimetype_fu to determine the  
> content-type as "image/jpeg".
>
> Best regards
>
> Peter De Berdt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to