Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8999937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:14:47+00:00 2026-06-16T00:14:47+00:00

I am creating an iOS app using Rubymotion. I am trying to make a

  • 0

I am creating an iOS app using Rubymotion. I am trying to make a multipart upload
of an image.

I use this code to make upload but I get error:

data = {token: "2xCGdzcuEeNzhst3Yaa8f", task: 1, message: "message", latitude: 1, longitude: 1}

    client = AFHTTPClient.alloc.initWithBaseURL(NSURL.URLWithString("http://api.example.com/api/v1/"))

        request = client.multipartFormRequestWithMethod('POST', path:"messages", parameters:data, constructingBodyWithBlock:lambda{ |form_data|
          image_data = UIImagePNGRepresentation(image.image)
          form_data.appendPartWithFileData(image_data, name:'new_avatar', fileName:'new_avatar.png', mimeType:'image/png')
        })

        operation = AFJSONRequestOperation.alloc.initWithRequest(request)
        operation.setCompletionBlockWithSuccess(lambda{ |operation, responseObject| puts 'all done!'})

I get this error:

undefined method `setCompletionBlockWithSuccess' for #<AFJSONRequestOperation:0xb227f00> (NoMethodError)

From what I can see, operation is a valid object and should have this method.
Am I missing something here?

Update 1

This is my updated code but when I run it the POST action does not seem to fire. Am I still missing any code? I do not get any errors either.

data = {token: "2xCGdzcuEeNzhs5tYaa8f", task: 1, message: "message", latitude: 1, longitude: 1}

    client = AFHTTPClient.alloc.initWithBaseURL(NSURL.URLWithString("http://api.example.com/api/v1/"))

    request = client.multipartFormRequestWithMethod('POST', path:"messages", parameters:data, constructingBodyWithBlock:lambda{ |form_data|
      image_data = UIImagePNGRepresentation(image.image)
      form_data.appendPartWithFileData(image_data, name:'new_avatar', fileName:'new_avatar.png', mimeType:'image/png')
    })

    operation = AFJSONRequestOperation.alloc.initWithRequest(request)
    operation.setCompletionBlockWithSuccess(lambda { |operation, responseObject| puts 'all done!'},
                                            failure: lambda { |operation, error| puts 'error' })

The request object outputs this:

<NSMutableURLRequest:195641792 - url: http://api.example.com/api/v1/messages, 
    headers: {"Content-Length"=>"118200", "Content-Type"=>"multipart/form-data; boundary=Boundary+0xAbCdEfGbOuNdArY", "Accept-Language"=>"en, fr, de, ja, nl, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8", "User-Agent"=>"theapp/1.0 (iPhone Simulator; iOS 6.0; Scale/1.00)"}, 
    cache policy: 0, Pipelining: false, main doc url: ,    timeout: 60.0, network service type: 0 >

The operation object outputs this:

<AFJSONRequestOperation:0xa78c660>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:14:48+00:00Added an answer on June 16, 2026 at 12:14 am

    The method signature is setCompletionBlockWithSuccess(lambda..., failure: lambda...) — you need to add a failure parameter. Something like this:

    operation.setCompletionBlockWithSuccess(lambda { |operation, responseObject| puts 'all done!'},
                                            failure: lambda { |operation, error| puts 'error' })
    

    Also, you’ll want to make sure to actually start the request operation:

    operation.start
    

    See https://github.com/AFNetworking/AFNetworking/blob/master/AFNetworking/AFJSONRequestOperation.m#L102-L103 for the definition of this method.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a transparent image on iOS using Quartz. However, this image shows
I am creating an iOS app using Rubymotion. In one of the views I
I am creating an iOS app with the help of Rubymotion. I am using
What's the workflow for creating an iOS app using Delphi-XE2. This is really a
Problem : I am creating an iOS chat app using the XMPPFramework and an
I am creating an app using iOS 5 SDK. I managed to push views
I am creating a quiz style app for iOS using phonegap. The app allows
I'm currently creating an iPhone app (Xcode 4.3.1, IOS 5) that could use Bluetooth
I'm creating an iOS app that needs to get a lot of information from
I am creating a calculator app and this is my first ios app, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.