3

I have use following example https://github.com/socketio/socket.io-client-swift how to send image using socket io?

4
  • What is the error? Code? Commented Jan 13, 2016 at 5:24
  • This may be Help you stackoverflow.com/questions/26331787/… Commented Jan 13, 2016 at 5: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. Commented Jan 13, 2016 at 5:27
  • i also need to know. if anyone have found the answer...please share Commented Jun 14, 2017 at 13:07

1 Answer 1

0

for example,you can send a image like this

//emit filename and size to server - (void)testButtonClicked { _fileName = @"[email protected]"; 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]; } } 
Sign up to request clarification or add additional context in comments.

1 Comment

are these start, upload, moredata methods?