I have use following example https://github.com/socketio/socket.io-client-swift how to send image using socket io?
Asked
Active
Viewed 2,611 times
3
-
What is the error? Code? – Bista Jan 13 '16 at 05:24
-
This may be Help you http://stackoverflow.com/questions/26331787/socket-io-node-js-simple-example-to-send-image-files-from-server-to-client – Hitesh Surani Jan 13 '16 at 05:25
-
actually there is no any error but i don't have any idea for sending an image.i have already google for it but not getting any hint. – Jan 13 '16 at 05:27
-
i also need to know. if anyone have found the answer...please share – Varinder Singh iPhone Dev Jun 14 '17 at 13:07
1 Answers
0
for example,you can send a image like this
//emit filename and size to server
- (void)testButtonClicked {
_fileName = @"001@3x.png";
NSString *path = [[NSBundle mainBundle] pathForResource:@"001@3x" ofType:@"png"];
_imgData = [NSData dataWithContentsOfFile:path];
float length = [_imgData length];
NSString *fileSizeString = [NSString stringWithFormat:@"%f", length];
NSArray *array = [NSArray arrayWithObject:@{@"Name": _fileName, @"Size":fileSizeString}];
[socket emit:@"start" withItems:array];
}
//server callback
[socket on:@"moreData" callback:^(NSArray *array, SocketAckEmitter *emitter) {
NSString *dataPosition = [array[0]objectForKey:@"position"];
[self uploadAvatarImage:dataPosition];
}];
// uploadImage Method
- (void)uploadAvatarImage:(NSString *)dataPosition {
NSString *path = [[NSBundle mainBundle] pathForResource:@"001@3x" ofType:@"png"];
_imgData = [NSData dataWithContentsOfFile:path];
NSString *imageString = [[NSString alloc]initWithData:_imgData encoding:NSStringEncodingConversionAllowLossy];
NSRange range;
if ([dataPosition intValue]<[_imgData length]) {
if ([_imgData length]-[dataPosition intValue]>5120) {
range.length = 5120;
}else {
range.length = [_imgData length]-[dataPosition intValue];
}
range.location =[dataPosition intValue];
NSString *subString = [imageString substringWithRange:range];
NSArray *array = [NSArray arrayWithObject:@{@"Name": _fileName, @"Segment":subString}];
[socket emit:@"upload" withItems:array];
}
}

weirdyu
- 294
- 1
- 9