Re: [ruby-81] how to post image data over using ActiveResource

From: user 5.
Sent on: Thursday, June 5, 2008 1:35 PM
I've had great success encoding images using Base64.encode, pushing
them into an XML element and transferring them that way. It's slow
both in the encoding and in the use of bandwidth, but it's nice in
that the data is embedded directly into the XML. Otherwise, you'll
need to do a multipart mime POST.

On Thu, Jun 5, 2008 at 1:22 PM, elmo <[address removed]> wrote:
> Hello folks,
> I'd appreciate a tip with a problem I'm facing:
> I've got an REST service that I'd like to be able to POST image data to.
> On the 'client' application I have:
> model:
> class Asset < ActiveResource
>        self.site += "/posts/:post_id"
> end
> controller:
> I'd like t o do the following:
>  @asset = Asset.new( :post_id => @post.id )  <<<----is this the correct way
> to initialize?
>  @asset.uploaded_data­ = params[:asset] <<-------i know it can't be this easy
>  @asset.save
>
> On the REST service application, the asset model is an attachement_fu -ized
> model:
> model
> class Asset < ActiveRecord::Base
>      has_attachment :content_type => :image,
>                   :storage => :file_system,
>                   :max_size => 500.kilobytes,
>                   :thumbnails => { :thumb => '100x100>' },
>                   :processor => :rmagick
>    validates_as_attachm­ent
> end
> controller:
>  @asset = @post.assets.new(par­ams[:asset])
> I get:
> NoMethodError (undefined method `content_type' for
> #<HashWithIndiffe­rentAccess:0x542a360­>):
>     /vendor/plugins/atta­chment_fu/lib/techno­weenie/attachment_fu­.rb:294:in
> `uploaded_data='
>
> Questions:
> 1. How do I correctly pass the image data to the REST controller via
> XML/ARES?
> 2. Do I have to set some headers?
> Thanks for your consideration.
>
>
>
>
>
>
> --
> Please Note: If you hit "REPLY", your message will be sent to everyone on
> this mailing list ([address removed])
> This message was sent by elmo ([address removed]) from The East Bay
> Ruby Meetup Group.
> To learn more about elmo, visit his/her member profile
> To unsubscribe or to update your mailing list settings, click here
>
> Meetup Support: [address removed]
> 632 Broadway New York NY 10012 USA

Our Sponsors

People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy