Skip to content

Instantly share code, notes, and snippets.

@gregfroese
Created November 21, 2012 13:04
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gregfroese/4124753 to your computer and use it in GitHub Desktop.
Save gregfroese/4124753 to your computer and use it in GitHub Desktop.
Posting an image in RubyMotion using BubbleWrap and saving it in Rails
## RubyMotion
imageData = UIImage.UIImageJPEGRepresentation(@image_view.image, 1)
encodedData = [imageData].pack("m0")
data["image"] = encodedData
BW::HTTP.post("http://localhost:3000/upload}", {payload: data}) do |response|
if response.ok?
end
end
## Rails backend
if params["image"]
unpack = params["image"].unpack("m0")
File.open("/tmp/image.jpg", "w+b") do |f|
f.write(unpack.first)
end
end
@travisvalentine
Copy link

Thanks for posting this. Just curious: when you submit this via RubyMotion to your server, is there an incredible lag time?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment