I am making an app in which user can chat & also send files from that app. But i am stuck on the point where user can send any file to the other user by attachment but i did not found any sample app or helping code for that so can any one help me to solve my problem.
Tell me some sample apps links and also the technique for upload and send file by browsing it from the iPhone using app.
Some suggestions for achieving this
Browse
Upload
Chat
Let me give you some suggestion first just upload the file from device like this
1.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
// Media is an image
picImage = [info objectForKey:UIImagePickerControllerOriginalImage];
NSString *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/image.jpg"]];
filePath = imagePath;
[UIImageJPEGRepresentation(picImage, 1.0) writeToFile:imagePath atomically:YES];
arrayMute = (NSMutableArray*) [self sendData:filePath]
}
}
2 Now just upload the media to webservices via ASIFormDataRequest then they will generate the link give back to the link. then u can send that link to another user via xmpp. and then other user can download that media.
-(NSMutableArray*)sendData:(NSString*)multiMData
{
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://194.158.1.25/IphoneVideoService/webservice.asmx/GetData1"]];
[request addRequestHeader: @"Content-Type" value:
@"application/x-www-form-urlencoded"];
[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setUploadProgressDelegate:progressToDownload];
[request setDidFinishSelector:@selector(uploadFinished:)];
[request setDidFinishSelector:@selector(requestFailed:)];
[request setDidFinishSelector:@selector(requestFinished:)];
[request setShouldContinueWhenAppEntersBackground:YES];
NSString *url = [[NSURL fileURLWithPath:multiMData] path];
[request setFile:url withFileName:[NSString stringWithFormat:@"Hello.jpeg"] andContentType:@"image/jpeg" forKey:@"file"];
[request setTimeOutSeconds:50000];
[request setRequestMethod:@"POST"];
[request startSynchronous];
SBJSON *sbJason = [[SBJSON alloc] init];
NSMutableArray *getUploadArray = [sbJason objectWithString:responseForMedia];
return getUploadArray;
}