正在将图像上传到 WCF json 服务

Uploading image to WCF json service

我在 wcf json 服务中有功能,需要两个参数来上传图片:

Public Function UploadDamageImage(ByVal UploadDamageImageRequest As UploadDamageImageRequest) As UploadDamageImageResponse

如何将图像作为字节参数发送到此函数?

我正在使用 AFHTTPRequestOperationManager

要将 UIImage 作为字节发送给函数,您可以先将 UIImage 转换为 NSData 对象,然后从中获取字节数组。

UIImage *image = // your image...
NSData *imgData = UIImagePNGRepresentation(image); 
NSString *byteArr = [data base64Encoding];

对于第二行代码,Apple Docs for UIImage说明:

...you can get an NSData object containing either a PNG or JPEG representation of the image data using the UIImagePNGRepresentation and UIImageJPEGRepresentation functions.