通过从iPhone浏览文件来上传和发送文件 [英] upload and send file by browsing a file from iphone

查看:258
本文介绍了通过从iPhone浏览文件来上传和发送文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个用户可以在其中聊天的应用程序;还可以从该应用发送文件.但是我陷入了困境,用户可以通过附件将任何文件发送给其他用户,但是我没有找到任何示例应用程序或帮助代码,因此任何人都可以帮助我解决我的问题.

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.

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

Tell me some sample apps links and also the technique for upload and send file by browsing it from the iPhone using app.

推荐答案

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

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现在只需通过ASIFormDataRequest将媒体上传到Web服务,然后它们将生成链接并提供给该链接.然后您可以通过xmpp将链接发送给其他用户.然后其他用户可以下载该媒体.

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;


 }

这篇关于通过从iPhone浏览文件来上传和发送文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆