2013-05-09 66 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; 


}