Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multipart POST? #4

Closed
dkrusenstrahle opened this issue Dec 11, 2012 · 3 comments
Closed

Multipart POST? #4

dkrusenstrahle opened this issue Dec 11, 2012 · 3 comments

Comments

@dkrusenstrahle
Copy link

Hello,

I am trying to upload an image to my remote Rails API (with paperclip).
How can I do a multipart POST using Afmotion?

Thanks!

@clayallsopp
Copy link
Collaborator

This has been added to AFMotion 0.3 (just released). The syntax looks like this: https://github.com/clayallsopp/afmotion#multipart-requests

It leaks the AFNetworking abstraction a bit, but it at least exposes a somewhat cleaner interface...would've been a bigger undertaking/hack to get it working with an ideal implementation =\

@dkrusenstrahle
Copy link
Author

Ah, perfect! How ca I monitor and display progress with the solution? I want to use a progressbar like I do with raw AFNetworking solution.

@clayallsopp
Copy link
Collaborator

I added a new API for this, update to AFMotion version 0.4:

client.multipart.post("avatars") do |result, form_data, progress|
  if form_data
    # Called before request runs
    # see: https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ
    form_data.appendPartWithFileData(data, name: "avatar", fileName:"avatar.png", mimeType: "image/png")
  elsif progress
    # 0.0 <= progress <= 1.0
    my_widget.update_progress(progress)
  elsif result.success?
    ...
  else
    ...
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants