Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios AFNetworking-上传视频和其他参数_Ios_Objective C_Afnetworking_Afhttpclient_Afhttprequestoperation - Fatal编程技术网

Ios AFNetworking-上传视频和其他参数

Ios AFNetworking-上传视频和其他参数,ios,objective-c,afnetworking,afhttpclient,afhttprequestoperation,Ios,Objective C,Afnetworking,Afhttpclient,Afhttprequestoperation,我想把视频和其他一些参数一起上传到web服务。我想将用户ID、视频ID和视频上传到web服务。上传时,除视频外的所有参数都被发送到web服务。我已经在web服务端进行了检查,视频没有随请求提供。我正在使用以下代码 - (void)uploadVideoAtLocalPath:(NSString *)videoPath videoID:(NSString *)videoID userID:(NSString *)userID { NSString *strServerURL = @"ww

我想把视频和其他一些参数一起上传到web服务。我想将用户ID视频ID视频上传到web服务。上传时,除视频外的所有参数都被发送到web服务。我已经在web服务端进行了检查,视频没有随请求提供。我正在使用以下代码

- (void)uploadVideoAtLocalPath:(NSString *)videoPath videoID:(NSString *)videoID userID:(NSString *)userID {

    NSString *strServerURL = @"www.mysite.com/user/uploadVideo";
    NSURL *URL = [NSURL URLWithString:strServerURL];
    AFHTTPClient *client = [AFHTTPClient clientWithBaseURL:URL];

    NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {

        // userID
        NSData *userIDData = [userID dataUsingEncoding:NSUTF8StringEncoding];
        [formData appendPartWithFormData:userIDData name:@"userID"];

        // videoID
        NSData *videoIDData = [videoID dataUsingEncoding:NSUTF8StringEncoding];
        [formData appendPartWithFormData:videoIDData name:@"videoID"];

        // video
        NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]];
        [formData appendPartWithFileData:videoData name:@"video" fileName:@"video.mov" mimeType:@"video/quicktime"];
    }];

    [request setURL:URL];
    [request setTimeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    [AFHTTPRequestOperation addAcceptableStatusCodes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(100, 500)]];
    [operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Response String: %@", operation.responseString);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Failure: %@", error);
    }];

    [client enqueueHTTPRequestOperation:operation];
}
-(void)上载VideoAtlocalPath:(NSString*)videoPath videoID:(NSString*)videoID用户ID:(NSString*)用户ID{
NSString*strServerURL=@“www.mysite.com/user/uploadVideo”;
NSURL*URL=[NSURL URLWithString:strServerURL];
AFHTTPClient*client=[AFHTTPClient-clientWithBaseURL:URL];
NSMutableURLRequest*request=[客户端multipartFormRequestWithMethod:@“POST”路径:@”“参数:nil constructingBodyWithBlock:^(id formData){
//用户ID
NSData*userIDData=[userID dataUsingEncoding:NSUTF8StringEncoding];
[formData appendPartWithFormData:userID数据名称:@“userID”];
//视频ID
NSData*videoIDData=[videoID数据使用编码:NSUTF8StringEncoding];
[formData appendPartWithFormData:videoID数据名称:@“videoID”];
//录像带
NSData*videoData=[NSData DATA WITH CONTENTS OFURL:[NSURL fileURLWithPath:videoPath]];
[formData appendPartWithFileData:videoData名称:@“video”文件名:@“video.mov”mimeType:@“video/quicktime”];
}];
[请求设置URL:URL];
[请求setTimeoutInterval:60.0];
[请求设置HttpMethod:@“POST”];
AFHTTPRequestOperation*操作=[[AFHTTPRequestOperation alloc]initWithRequest:request];
[AFHTTPRequestOperation addAcceptableStatusCodes:[NSIndexSet IndexetWithindexInsRange:NSMakeRange(100500)];
[操作setCompletionBlockWithSuccess:^(AFHTTPRequestOperation*操作,id响应对象){
NSLog(@“响应字符串:%@”,operation.responseString);
}失败:^(AFHTTPRequestOperation*操作,NSError*错误){
NSLog(@“故障:%@”,错误);
}];
[客户端排队HttpRequestOperation:operation];
}
有人能告诉我我做的是否正确吗?如果没有,请告诉我如何将视频和其他参数一起上传到web服务


谢谢大家

我不擅长这种方法。我也有同样的问题。但是,我已经将其修复为POST&GET方法的混合。我只是将我的参数作为GET方法发送,如下所示-

NSString*strServerURL=[NSString stringWithFormat:@“www.mysite.com/user/uploadVideo&userID=%d&videoID=%d”,1,55]

并且,按照您的方法以POST方式发送我的视频数据-

NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:@"" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {

    // video
    NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:videoPath]];
    [formData appendPartWithFileData:videoData name:@"video" fileName:@"video.mov" mimeType:@"video/quicktime"];
}];
NSMutableURLRequest*request=[client multipartFormRequestWithMethod:@“POST”path:@”参数:nil constructionbodywithblock:^(id formData){
//录像带
NSData*videoData=[NSData DATA WITH CONTENTS OFURL:[NSURL fileURLWithPath:videoPath]];
[formData appendPartWithFileData:videoData名称:@“video”文件名:@“video.mov”mimeType:@“video/quicktime”];
}];
您最好尝试修改您的Web服务,并尝试上述方法。它应该有效


干杯

您是否检查了
videoData
是否为nil?是否可以尝试将userID和videoID包含在NSDictionary中,并将其放入方法multipartFormRequestWithMethod的参数中,而不是放入nil?@AttilaH:Hi,videoData不是nil。我查过了。谢谢。@verbumdei,嗨,我也试过了,但没用。无论如何,我会再试一次(可能是我以前没有做对),并让你知道。谢谢。谢谢@EmptyStack,通过使用您的代码,我可以将图像上传到我的服务器。