Interesting. This is definitely a step in a productive direction and I
am very thankful for the suggestions that you have given. It's not
*quite* doing the trick, but it's the closest I've been so far.
Here's the scoop:
First, to do this, I had to make :content_type
and :filename :attr_accessible and make a setter for temp_data in my
asset class, since it's not a setter attribute. This method calls
set_temp_data in attachment_fu, like so:
def temp_data=
set_temp_data(data)
end
I then followed your suggestion in the controller, like so, but
getting the mime_type from mimetype_fu, in case it's not always "image/
jpeg"
image_params = {:temp_data => params
['image_uploaded_data'], :filename=> params
['image_uploaded_data'], :content_type => File.mime_type?(params
['image_uploaded_data'])}
Note that each of values is the same field: params
['image_uploaded_data'] is the string of the filename that comes in.
At this point, I ran the code and for the first time the process
worked: the image validated, and it was stored on s3. However, the
image itself was not the image exported from Flash: it was a jpeg *of*
the string of filename. You can see it here:
http://s3.amazonaws.com/canvasband_development/assets/255/v1/1152215550.jpg
Weird. So I looked more closely at attachment_fu, and saw that in the
uploaded_data= method, the seemingly relevant lines here pass the data
from the file to set_temp_data, like so:
(line 334)
if file_data.is_a?(StringIO)
file_data.rewind
set_temp_data file_data.read
else
self.temp_paths.unshift file_data
end
So I switched my temp data setter to mimic that:
def temp_data=(data)
data.rewind
set_temp_data(data.read)
end
and tried again, at which point I received the error:
NoMethodError (undefined method `rewind' for "1152233660.jpg":String)
So I then tried to convert the string to a stringIO object,
def temp_data=(data)
datastr = StringIO.new(data)
datastr.rewind
set_temp_data(datastr.read)
end
Which then worked again -- ie, saved and uploaded the image -- except
the "image" it saved was still a jpeg of the filename, again visible
on s3
http://s3.amazonaws.com/canvasband_development/assets/263/v1/1152241736_thumb.jpg,
but not what Flash sent in.
Which seems to bring me back to the original problem, namely: despite
the fact that the binary data is coming into the application, by the
time I'm in the controller I can't figure out how to access that data,
and am only managing to get this pseudo-image.
Is there anything else you can think of here?
Thanks again for your input thus far,
Sarah
On Jan 15, 5:06 pm, Peter De Berdt <[email protected]> wrote:
> On 15 Jan 2009, at 19:55, sarah wrote:
>
>
>
> > 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
>
> > 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.
>
> How about:
>
> image_params = {:temp_data => params['image_uploaded_data'],
> :filename => "whateveruwant",
> :content_type => "image/jpeg"
> }
> image = @visual_note.build_image(image_params.merge(:created_by =>
> current_user))
> if image.valid?
> #do stuff
> else
> #errors
> end
>
> Means the data that comes from Flash will be processed and you
> manually set the other fields.
>
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---