AFNetworking Uploading a file

后端 未结 1 896
醉梦人生
醉梦人生 2020-12-03 00:15

Does any one have a full implementation of uploading a file using AFNetworking. I have found some code on the internet but it is incomplete. The code I have found is here:

相关标签:
1条回答
  • 2020-12-03 00:44

    First, make sure you have the latest version of AFNetworking downloaded.

    AFHTTPRequestOperation +HTTPRequestOperationWithRequest:success:failure: was removed a few versions back. Instead, you can do [[AFHTTPRequestOperation alloc] initWithRequest:...] and then set the completionBlock with either the straight property accessor (operation.completionBlock = ^{...}), or with -setCompletionBlockWithSuccess:failure:. Keep in mind that completion blocks execute after the request has finished downloading.

    As for the multipart form block, -appendWithFileData:mimeType:name was also removed a while back. The method you want is -appendPartWithFileData:name:fileName:mimeType:.

    Make those two changes and everything should work.

    0 讨论(0)
提交回复
热议问题