Uploading Image NSData via POST and NSURLSession

亡梦爱人 提交于 2019-12-03 06:34:45

The problem was in NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromData:imageData completionHandler:...]

NSURLSessionUploadTask ignores the request body provided and adds the fromData: parameter as the request body. However, I was just providing the image data and not the properly formatted request body...

The fixed code is then NSURLSessionUploadTask *uploadTask = [session uploadTaskWithRequest:request fromData:body completionHandler:...]

I'll leave my answer up in case anyone else stumbles across this problem again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!