2013-05-09 99 views
0

的文件来上传和发送文件我正在制作一个应用程序,用户可以在其中聊天&也从该应用程序发送文件。但我坚持的点用户可以通过附件发送任何文件给其他用户,但我没有找到任何示例应用程序或帮助代码,所以任何人都可以帮助我解决我的问题。通过浏览iphone

告诉我一些示例应用程序链接,以及通过使用应用程序从iPhone浏览来上传和发送文件的技巧。

+0

参考xmpp框架 – Anil 2013-05-09 05:22:12

+0

chating with xmpp framework? – 2013-05-09 05:28:00

回答

0

让我给你一些建议,首先刚刚从设备上传的文件这样

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现在只需通过ASIFormDataRequest将媒体上传到webservices,然后他们将生成链接返回链接。那么你可以通过xmpp将该链接发送给其他用户。然后其他用户可以下载该媒体。

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


}