通过ASIFormDataRequest将Mp4视频发送到PHP服务器

时间:2012-11-01 05:46:54

标签: iphone objective-c ios ftp asiformdatarequest

这里我发送带有一些参数的文件路径或文件。但是服务器没有收到视频。那么代码中的任何问题呢?或者你想要添加的东西。那请告诉我。任何委托方法,你想告诉我哪里出现错误或设置响应。

NSString *path = [[NSBundle mainBundle] pathForResource:@"hangover" ofType:@"mp4"];

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://156.75.28.172:52/aircas/RestServices/fileUpload"]];

[request setPostValue:filename forKey:@"name"]; 

[request setPostValue:@"GUnit" forKey:@"title"];
[request setPostValue:@"133" forKey:@"user_id"]; 
[request setPostValue:@"8953d0e1c97ef83c9f0aff47" forKey:@"token"]; 
[request setPostValue:@"video song" forKey:@"desc"]; 
[request setPostValue:@"34" forKey:@"video_id"]; 
[request setPostValue:@"0" forKey:@"is_private"]; 

[request setFile:path forKey:@"video"];

[request setTimeOutSeconds:500]; 
[request setRequestMethod:@"POST"];

[request startSynchronous];

2 个答案:

答案 0 :(得分:5)

在代码中添加以下代码,然后您可以编写2个委托方法并处理响应。

[request setDelegate:self];
[request setDidFailSelector:@selector(uploadFailed:)];
[request setDidFinishSelector:@selector(uploadFinished:)];

- (void) uploadFailed:(ASIHTTPRequest *)request 
{
    //Upload succeeded;
}

- (void) uploadFinished:(ASIHTTPRequest *)request 
{
    //Upload failed;
    NSError *error = [request error];
    NSLog(@"Error Description-->%@",[error localizedDescription]);
}

为ASIHttpRequest please see documentation提供深入视图。它有很好的记录。

答案 1 :(得分:5)

试试这个......

NSString *path = [[NSBundle mainBundle] pathForResource:@"hangover" ofType:@"mp4"];
    NSURL *fileURL = [NSURL fileURLWithPath:path];
        NSData *movieData = [NSData dataWithContentsOfURL:fileURL];

    ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://156.75.28.172:52/aircas/RestServices/fileUpload"]];

     [request setPostValue:filename forKey:@"name"]; 

    [request setPostValue:@"GUnit" forKey:@"title"];
     [request setPostValue:@"133" forKey:@"user_id"]; 
     [request setPostValue:@"8953d0e1c97ef83c9f0aff47" forKey:@"token"]; 
     [request setPostValue:@"video song" forKey:@"desc"]; 
    [request setPostValue:@"34" forKey:@"video_id"]; 
    [request setPostValue:@"0" forKey:@"is_private"]; 

    [self.request setData:movieData withFileName:@"hangover.mp4" andContentType:@"multipart/form-data" forKey:@"video"];

    [request setTimeOutSeconds:500]; 
    [request setRequestMethod:@"POST"];

    [request startSynchronous];

希望它有所帮助。