【问题标题】:How to convert UIImage or NSData to byte Array and post to server?如何将 UIImage 或 NSData 转换为字节数组并发布到服务器?
【发布时间】:2013-10-07 11:02:38
【问题描述】:

如何将UIImageNSDate 转换为字节数组并发布到服务器。 在我的应用程序中,我必须将 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];

【问题讨论】:

标签: ios post bytearray nsdata asiformdatarequest


【解决方案1】:

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

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

       [request appendPostData:self.dataImage];

【讨论】:

    【解决方案2】:

    像这样尝试,

        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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 2012-05-28
      • 1970-01-01
      • 2015-06-13
      • 1970-01-01
      相关资源
      最近更新 更多