Upload an image with AFNetworking 2.0

后端 未结 2 2056
暖寄归人
暖寄归人 2020-12-28 21:18

I can\'t understand why this is so hard. All the tutorials and articles online seem to be talking about the 1.0 api, which is pretty useless.

I\'ve tried a few diffe

2条回答
  •  悲哀的现实
    2020-12-28 22:04

    What Ray Lillywhite describes works perfectly fine (I would've made a comment on his post, but my reputation is too low).

    1. Get the correct version of AFNetworking, containing this fix for updating progress when using multipart requests. At the moment of writing, that version is HEAD.
    2. Create a NSMutableURLRequest with the help of multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:error:.
      • Build your form data with the help of one of the appendPartWith... methods.
    3. Get a (upload) data task by calling the right uploadTaskWith... method. You NEED to use uploadTaskWithStreamedRequest:progress:completionHandler: if you want to use the NSProgress input parameter.

提交回复
热议问题