Dustin Anderson
2007-Dec-08 18:51 UTC
[Facebooker-talk] Uploading photos using facebook & attachment_fu
Hi All, I''m trying to use a form to upload a photo that I will save using attachment_fu. I''m very new to Facebookr so I apologize if this is covered somewhere, but I''m kind of stumped. Here''s what I''m doing now: <% facebook_form_for(:my_object, :url => { :action => ''upload_photo'', :id => params[:id] }, :html => { :multipart => true }) do |f| -%> <%= radio_button_tag ''my_object[my_param]'', "value" %> <%= file_field_tag "photo[uploaded_data]" %> <% end %> Now that I''ve typed this out I''m realizing that the facebook_form_for probably isn''t doing anything for me since i''m not using the f. helpers, but I have two models that I''m trying to save data for.nonetheless, here''s my problem: The params are passing "photo"=>{"uploaded_data"=>"sample.jpg"} and the error that I''m getting is: NoMethodError (undefined method `content_type'' for "sample.jpg":String) Again, I''m using attachment_fu to handle the image processing. It was working before I tried porting it over to facebook so I think I have attachment_fu configured properly. Any ideas on what I''m missing? Many thanks, Dustin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20071208/6a917d1b/attachment.html
Mike Mangino
2007-Dec-09 00:20 UTC
[Facebooker-talk] Uploading photos using facebook & attachment_fu
Facebook doesn''t pass through multipart uploads. You can add a :canvas=>true to your route to bypass Facebook on the form POST and then redirect after the upload. You will probably need to include the fb_sig parameters in your form. Mike On Dec 8, 2007, at 12:51 PM, Dustin Anderson wrote:> Hi All, > > I''m trying to use a form to upload a photo that I will save using > attachment_fu. I''m very new to Facebookr so I apologize if this is > covered somewhere, but I''m kind of stumped. > > Here''s what I''m doing now: > <% facebook_form_for(:my_object, :url => { :action => > ''upload_photo'', :id => params[:id] }, :html => { :multipart => > true }) do |f| -%> > > <%= radio_button_tag ''my_object[my_param]'', "value" %> > > <%= file_field_tag "photo[uploaded_data]" %> > > <% end %> > > Now that I''ve typed this out I''m realizing that the > facebook_form_for probably isn''t doing anything for me since i''m not > using the f. helpers, but I have two models that I''m trying to save > data for.nonetheless, here''s my problem: > > The params are passing "photo"=>{"uploaded_data"=>"sample.jpg"} and > the error that I''m getting is: > NoMethodError (undefined method `content_type'' for > "sample.jpg":String) > > Again, I''m using attachment_fu to handle the image processing. It > was working before I tried porting it over to facebook so I think I > have attachment_fu configured properly. > > Any ideas on what I''m missing? > > Many thanks, > Dustin > > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk-- Mike Mangino http://www.elevatedrails.com
Dustin Anderson
2007-Dec-09 06:19 UTC
[Facebooker-talk] Uploading photos using facebook & attachment_fu
Awesome, thanks Mike - that was a huge help. Now the file is saving to the database and I have it redirecting. I have to say that the way I have it working seems like it''s really hack-ey. Here''s basically what my CONTROLLER CODE looks like: ####Controller:### def create @my_object = MyObject.new @my_object.photo = Photo.new(params[:photo]) @my_object.photo.save if @comparison.save #### AND THIS IS WHERE IT GETS WEIRD- DO I REALLY HAVE TO PASS ALL THESE PARAMS ALONG?### redirect_to :action => "get_other_pic", :fb_sig => params[:fb_sig], :fb_sig_time => params[:fb_sig_time], :fb_sig_session_key => params[:fb_sig_session_key], :fb_sig_expires => params[:fb_sig_expires], :fb_sig_added => params[:fb_sig_added], :fb_sig_api_key => params[:fb_sig_api_key], :fb_sig_user => params[:fb_sig_user], :fb_sig_profile_update_time => params[:fb_sig_profile_update_time], :id => @my_object.id, :canvas => true else render :action => :new end end ###END CONTROLLER### Oh, and here''s basically what MY VIEW LOOKS LIKE: #FYI, :canvas => false worked for me, not :canvas => true - maybe I misunderstood? <% form_for(:comparison, :url => { :controller => ''my_object'', :action => ''update'', :canvas => false, :only_path => false, :host => "www.myhost.com" }, :html => { :multipart => true }) do |f| -%> Thanks again, I was really wondering if I was barking up the wrong tree... and I wasn''t getting anywhere for a while. And now, my only question is - am I missing something? It seems like passing all these fb_sig_* parameters isn''t very DRY and Facebookr might have some abstraction for it? -Dustin On Dec 8, 2007 6:20 PM, Mike Mangino <mmangino at elevatedrails.com> wrote:> Facebook doesn''t pass through multipart uploads. You can add > a :canvas=>true to your route to bypass Facebook on the form POST and > then redirect after the upload. You will probably need to include the > fb_sig parameters in your form. > > Mike > > > On Dec 8, 2007, at 12:51 PM, Dustin Anderson wrote: > > > Hi All, > > > > I''m trying to use a form to upload a photo that I will save using > > attachment_fu. I''m very new to Facebookr so I apologize if this is > > covered somewhere, but I''m kind of stumped. > > > > Here''s what I''m doing now: > > <% facebook_form_for(:my_object, :url => { :action => > > ''upload_photo'', :id => params[:id] }, :html => { :multipart => > > true }) do |f| -%> > > > > <%= radio_button_tag ''my_object[my_param]'', "value" %> > > > > <%= file_field_tag "photo[uploaded_data]" %> > > > > <% end %> > > > > Now that I''ve typed this out I''m realizing that the > > facebook_form_for probably isn''t doing anything for me since i''m not > > using the f. helpers, but I have two models that I''m trying to save > > data for.nonetheless, here''s my problem: > > > > The params are passing "photo"=>{"uploaded_data"=>"sample.jpg"} and > > the error that I''m getting is: > > NoMethodError (undefined method `content_type'' for > > "sample.jpg":String) > > > > Again, I''m using attachment_fu to handle the image processing. It > > was working before I tried porting it over to facebook so I think I > > have attachment_fu configured properly. > > > > Any ideas on what I''m missing? > > > > Many thanks, > > Dustin > > > > > > _______________________________________________ > > Facebooker-talk mailing list > > Facebooker-talk at rubyforge.org > > http://rubyforge.org/mailman/listinfo/facebooker-talk > > -- > Mike Mangino > http://www.elevatedrails.com > >
Dustin Anderson
2007-Dec-09 20:20 UTC
[Facebooker-talk] Uploading photos using facebook & attachment_fu
Ahh, so it turns out I didn''t need any of the fb_sig stuff at all - I just needed to tell it canvas => false on the file upload (in the form) and then canvas => true in the redirect (in the controller)- again, thanks Mike. Slowly but surely, I''m starting to get this... Now, here''s another quirk - there seems to be a problem with the rails image_tag helper not working with the location of my file uploads... this may be just a problem with how attachment_fu saves attachments, and facebook''s requirement to have the relative_url_root. I have attachment_fu putting the model attachments in public/system/photos In the view, when I call <%= image_tag @my_model.photo.public_filename %>, it renders http://www.myhost.com/my_facebook_app/system/photos/0000/0083/uploaded_image.jpg But, the file isn''t there, the file is in: http://www.myhost.com/system/photos/0000/0083/uploaded_image.jpg It''s the same path without the FACEBOOKER_RELATIVE_URL_ROOT, which for me is: ENV[''FACEBOOKER_RELATIVE_URL_ROOT''] = ''my_facebook_app'' Anyway, I had to make a helper to sub out the /my_facebook_app/ of the path. It seems like image_tag should just work since facebook_image_tag says its deprecated... but there seems to be a quirk if you are using something like attachment_fu which doesn''t use ENV[''FACEBOOKER_RELATIVE_URL_ROOT'']. If anyone has any knowledge of what''s happening here, I''d love to get some advice or help... for now, I''m just going to stick with my helper which seems to be working. Thanks again, Dustin On Dec 9, 2007 12:19 AM, Dustin Anderson <dkanderson at gmail.com> wrote:> Awesome, thanks Mike - that was a huge help. Now the file is saving > to the database and I have it redirecting. I have to say that the way > I have it working seems like it''s really hack-ey. > > Here''s basically what my CONTROLLER CODE looks like: > ####Controller:### > def create > @my_object = MyObject.new > @my_object.photo = Photo.new(params[:photo]) > @my_object.photo.save > if @comparison.save > #### AND THIS IS WHERE IT GETS WEIRD- DO I REALLY HAVE TO PASS ALL > THESE PARAMS ALONG?### > redirect_to :action => "get_other_pic", > :fb_sig => params[:fb_sig], > :fb_sig_time => params[:fb_sig_time], > :fb_sig_session_key => params[:fb_sig_session_key], > :fb_sig_expires => params[:fb_sig_expires], > :fb_sig_added => params[:fb_sig_added], > :fb_sig_api_key => params[:fb_sig_api_key], > :fb_sig_user => params[:fb_sig_user], > :fb_sig_profile_update_time => params[:fb_sig_profile_update_time], > :id => @my_object.id, > :canvas => true > else > render :action => :new > end > end > ###END CONTROLLER### > Oh, and here''s basically what MY VIEW LOOKS LIKE: > #FYI, :canvas => false worked for me, not :canvas => true - maybe I > misunderstood? > > <% form_for(:comparison, > :url => { :controller => ''my_object'', :action => ''update'', :canvas => > false, :only_path => false, :host => "www.myhost.com" }, > :html => { :multipart => true }) do |f| -%> > > Thanks again, I was really wondering if I was barking up the wrong > tree... and I wasn''t getting anywhere for a while. And now, my only > question is - am I missing something? It seems like passing all these > fb_sig_* parameters isn''t very DRY and Facebookr might have some > abstraction for it? > > -Dustin > > > On Dec 8, 2007 6:20 PM, Mike Mangino <mmangino at elevatedrails.com> wrote: > > Facebook doesn''t pass through multipart uploads. You can add > > a :canvas=>true to your route to bypass Facebook on the form POST and > > then redirect after the upload. You will probably need to include the > > fb_sig parameters in your form. > > > > Mike > > > > > > On Dec 8, 2007, at 12:51 PM, Dustin Anderson wrote: > > > > > Hi All, > > > > > > I''m trying to use a form to upload a photo that I will save using > > > attachment_fu. I''m very new to Facebookr so I apologize if this is > > > covered somewhere, but I''m kind of stumped. > > > > > > Here''s what I''m doing now: > > > <% facebook_form_for(:my_object, :url => { :action => > > > ''upload_photo'', :id => params[:id] }, :html => { :multipart => > > > true }) do |f| -%> > > > > > > <%= radio_button_tag ''my_object[my_param]'', "value" %> > > > > > > <%= file_field_tag "photo[uploaded_data]" %> > > > > > > <% end %> > > > > > > Now that I''ve typed this out I''m realizing that the > > > facebook_form_for probably isn''t doing anything for me since i''m not > > > using the f. helpers, but I have two models that I''m trying to save > > > data for.nonetheless, here''s my problem: > > > > > > The params are passing "photo"=>{"uploaded_data"=>"sample.jpg"} and > > > the error that I''m getting is: > > > NoMethodError (undefined method `content_type'' for > > > "sample.jpg":String) > > > > > > Again, I''m using attachment_fu to handle the image processing. It > > > was working before I tried porting it over to facebook so I think I > > > have attachment_fu configured properly. > > > > > > Any ideas on what I''m missing? > > > > > > Many thanks, > > > Dustin > > > > > > > > > _______________________________________________ > > > Facebooker-talk mailing list > > > Facebooker-talk at rubyforge.org > > > http://rubyforge.org/mailman/listinfo/facebooker-talk > > > > -- > > Mike Mangino > > http://www.elevatedrails.com > > > > >