[英]Convert an image (png/jpeg) to multipart object in iOS
I have an app thats needs to connect to a backend server. 我有一个需要连接到后端服务器的应用程序。 The Java developer tells me the app must send an image as a multipart object.
Java开发人员告诉我,应用程序必须将图像作为多部分对象发送。 I've spent hours searching the web for information on converting images to multipart files in ios but I've found nothing useful.
我花了数小时在网上搜索有关在ios中将图像转换为多部分文件的信息,但是我发现没有任何用处。 I have no prior knowledge of multipart also.
我也没有多部分的先验知识。
Could someone post a sample code or point me in the right direction/necessary steps involved? 有人可以张贴示例代码或向我指出正确的方向/涉及的必要步骤吗? Or share any knowledge that they may have in regards to sending images as multipart objects.
或分享他们在将图像作为多部分对象发送方面可能拥有的任何知识。
Sorry I hope this isnt a bit vague and I can supply more information if needed. 抱歉,我希望这不太模糊,如果需要,我可以提供更多信息。
-the server uses json -服务器使用json
You might consider using something like AFNetworking , which has a http client class that can take care of the multipart data upload for you. 您可能会考虑使用类似AFNetworking之类的东西,它具有一个http客户端类,可以为您处理分段数据上传。
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"upload/"
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:yourData
name:@"attachment"
fileName:@"attachment.jpg"
mimeType:@"image/jpg"];
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.