0

I am building an iOS app using Rubymotion. I need to let the user snap a photo with the camera and then upload it to a Rails 3 backend (with Paperclip) using the BubbleWrap Http module (or any better?).

How can I do this?

This is my code:

controller = UIImagePickerController.alloc.init
controller.sourceType = UIImagePickerControllerSourceTypeCamera
controller.mediaTypes = [KUTTypeImage]
controller.allowsEditing = true
controller.delegate = self

self.navigationController.presentModalViewController(controller, animated:true)

This I use after taking the shot:

metadata = info.objectForKey(UIImagePickerControllerMediaMetadata)
the_image = info.objectForKey(UIImagePickerControllerOriginalImage)

image = view.viewWithTag 3
image.image = the_image

picker.dismissModalViewControllerAnimated(true)

This is my upload code:

data = {access_token: TOKEN, id: task, image: image}

   BubbleWrap::HTTP.get("#{URL}#{project}/message", {payload: data}) do |response|
      if response.ok?
        json = BubbleWrap::JSON.parse(response.body)
        if json['total'] > 0
          infos = json['taskinfos'].map {|ej| self.from_json(ej["taskinfo"])} 
          block.call(true, infos)
        else
          block.call(false, nil)
        end
      else
        block.call(false, nil)
      end
    end
Jonathan Clark
  • 19,726
  • 29
  • 111
  • 175
  • 1
    Jonathan, you ask a lot of really broad questions with a lot of potential answers. I don't know that they are appropriate for Stackoverflow. – Jamon Holmgren Dec 12 '12 at 00:10
  • With all due respect Jamon. This is not a really broad question. It is very narrow, Rubymotion and Image upload. – Jonathan Clark Dec 12 '12 at 07:43
  • I am trying to learn Rubymotion so unfortunately there will be many questions since the official documentation is very lacking. – Jonathan Clark Dec 12 '12 at 18:00
  • I feel your pain on the iOS documentation, but "How can I do this?" is overly broad. Try some things and if they don't work then come to Stackoverflow and ask. You'll get better answers that way. – Jamon Holmgren Dec 12 '12 at 18:08
  • I don't mind answering your more specific questions (I have several times already) but I'm just asking you to be more specific and try some things before posting here. – Jamon Holmgren Dec 12 '12 at 18:10

1 Answers1

1

Uploading images should be done via a POST request and not a GET request like you have done. Most web servers have a limit to how big a GET request can be, and it is usually 8k, read here for more info maximum length of HTTP GET request? , so it's not suitable for images.

Play around with bubble motion and look at the requests in the log files on the server to see what comes out. Try to make the request look like a request made from within rails itself, ie from a web page where you upload to the the controller.

So you could change the request to POST and let people know what error messages you get.

Community
  • 1
  • 1
cmrichards
  • 1,725
  • 1
  • 19
  • 28