如何将UIImage
或NSDate
转换为字节数组并发布到服务器。
在我的应用程序中,我必须将UIImage
转换为字节数组,我必须发布。
我正在使用的ASIFormDataRequest
。
我的代码是:
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];
答案 0 :(得分:1)
尝试这样,
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];
答案 1 :(得分:0)
我通过替换
解决了这个问题 [request addData:imageData withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];
带
[request appendPostData:self.dataImage];