0

如何将UIImageor转换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];
4

2 回答 2

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];
于 2013-10-01T11:17:26.153 回答
0

我通过替换解决了这个问题

         [request addData:imageData withFileName:@"Image.png" andContentType:@"image/png" forKey:@"photo"];

       [request appendPostData:self.dataImage];
于 2013-10-01T14:01:11.820 回答