RestKit图像上传到Web服务(RestKit image upload to web service)

编程入门 行业动态 更新时间:2024-10-26 10:30:55
RestKit图像上传到Web服务(RestKit image upload to web service)

对于客户项目,我需要将图像(作为个人资料图片)上传到后端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&

本文发布于:2023-08-07 23:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1466156.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图像   Web   RestKit   image   service

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!