我正在尝试将图像从 mydevice 发送到服务器使用 Socket。
我使用此代码将图像转换为字节。之后,我将字节发送到服务器:
- (IBAction)btnSend:(id)sender {
UIImage *image = [UIImage imageNamed:@"button.png"];
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
// NSLog(@"data: %@", imageData);
NSString *string = [NSString stringWithFormat:@"%@", imageData];
NSDictionary *deviceDic = @{@"RequestType": @"5",
@"StringData":string};
NSData* bodyData = [NSJSONSerialization dataWithJSONObject:deviceDic
options:kNilOptions error:nil];
[socket writeData:bodyData withTimeout:-1 tag:0];
}
但是,我的字节数组非常大,所以我想将字节发送到服务器。