Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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
从iPhone应用程序通过AFN网络上传视频_Iphone_Ios_Http_File Upload_Afnetworking - Fatal编程技术网

从iPhone应用程序通过AFN网络上传视频

从iPhone应用程序通过AFN网络上传视频,iphone,ios,http,file-upload,afnetworking,Iphone,Ios,Http,File Upload,Afnetworking,我正在从我的iPhone应用程序向服务器发布一个视频文件。目前我正在使用HTTP POST方法。 我想学习如何使用AFN网络上传。 希望有人能帮助我 以下是我现在使用的HTTP发布示例: NSString *urlString =@"http://example.com/demo/upload_video"; NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease]; [request setU

我正在从我的iPhone应用程序向服务器发布一个视频文件。目前我正在使用HTTP POST方法。 我想学习如何使用AFN网络上传。 希望有人能帮助我

以下是我现在使用的HTTP发布示例:

NSString *urlString =@"http://example.com/demo/upload_video";

NSMutableURLRequest *request= [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];

//userid 
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"user_id\"\r\n\r\n%@", appDelegate.userid] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];

conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
    webData = [[NSMutableData data] retain];
}    

您正在添加此
[httpClient排队HttpRequestOperation:operation]在代码末尾

使用以下代码作为示例:

NSURL *url = [NSURL URLWithString:@"http://api-base-url.com"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"avatar.jpg"], 0.5);
NSMutableURLRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:@"/upload" parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
    [formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
}];

不,你可以问我这个comments@SplatterStrikes请参阅上面的示例MKNetworkKit也是在服务器上发布视频的好选择。检查可能会帮助您
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
[operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
    NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[httpClient enqueueHTTPRequestOperation:operation];