通过浏览iphone中的文件来上传和发送文件

时间:2013-05-09 05:14:57

标签: iphone ios xcode file-upload

我正在创建一个用户可以聊天的应用程序。还从该应用程序发送文件。但我仍然坚持用户可以通过附件将任何文件发送给其他用户,但我没有找到任何示例应用程序或帮助代码,所以任何人都可以帮我解决我的问题。

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

2 个答案:

答案 0 :(得分:0)

实现此目的的一些建议

Browse

Upload

Chat

答案 1 :(得分: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;


 }