[英]How to convert UIImage or NSData to byte Array and post to server?
How to convert UIImage
or NSDate
to byte array and post to server. 如何将UIImage
或NSDate
转换为字节数组并发布到服务器。 In my app i have to convert UIImage
to byte array and i have to post. 在我的应用程序中,我必须将UIImage
转换为字节数组,并且必须发布。
for post i am using as ASIFormDataRequest
. 对于帖子,我正在使用ASIFormDataRequest
。
My code is: 我的代码是:
NSUInteger len = [self.dataImage length];
Byte *byteData= (Byte*)malloc(len); //converting date to byte array
[self.dataImage getBytes:byteData length:len];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlStr]];
[request setRequestMethod:@"POST"];
[request addData:self.dataImage withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];
[request setDelegate:self];
[request startAsynchronous];
Try Like this, 像这样尝试
NSData *imageData = UIImagePNGRepresentation(self.dataImage ,0.1);
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:urlStr]];
[request setRequestMethod:@"POST"];
[request addData:imageData withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];
[request setDelegate:self];
[request startAsynchronous];
I solved this by replacing 我通过替换解决了这个问题
[request addData:imageData withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];
with 同
[request appendPostData:self.dataImage];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.