对于客户项目,我需要将图像(作为个人资料图片)上传到后端Web服务。 该服务只需要HTTP-POST请求正文中的图像。
当我在我的应用程序的其余部分使用RestKit时,我想使用该库进行上传。 STO和Google只使用多部分表单给了我答案。
是否有一种解决方法可以跳过多部分表单并只发送图像(不附加到对象)?
我正在使用RestKit 0.20.3并为iOS 7开发。
For a customer project, I need to upload an image (as a profile picture) to a backend web service. That service only wants the image in the body of the HTTP-POST request.
As I am using RestKit in the rest of my application, I want to use the library for this upload. STO and Google only gave me answers by using a multipart-form.
Is there a workaround to skip the multipart-form and just send the image (without being attached to an object)?
I am using RestKit 0.20.3 and develop for iOS 7.
最满意答案
不要使用RestKit,没有涉及映射,因此不合适。 RestKit使用适合此任务的AFNetworking,因此请使用它。
如果您只想在帖子正文中使用图像,请获取适当编码的图像数据并将其设置为NSMutableURLRequest的HTTPBody 。 然后使用AFHTTPRequestOperation发送请求。
Don't use RestKit for this, there is no mapping involved so it is not appropriate. RestKit uses AFNetworking which is appropriate for this task so use that instead.
If you just want the image in the post body, get the appropriately encoded image data and set it as the HTTPBody of your NSMutableURLRequest. Then use AFHTTPRequestOperation to send the request.
更多推荐
RestKit,图像,image,电脑培训,计算机培训,IT培训"/> <meta name="description&
发布评论