【发布时间】:2025-12-16 11:10:01
【问题描述】:
我必须从图库上传视频并将其发送到服务器分段。
当我从画廊中选择电影时,有这些信息:
self.videoDictionary = {
UIImagePickerControllerMediaType = "public.movie";
UIImagePickerControllerMediaURL = "file:///Users/alin/Library/Application%20Support/iPhone%20Simulator/7.0.3/Applications/714D0B71-80EA-4B6C-9ACF-A287C8F40121/tmp/trim.FF287468-B25E-4EEA-8EAB-A485842476FA.MOV";
UIImagePickerControllerReferenceURL = "assets-library://asset/asset.MOV?id=393E740F-B7F4-46DA-BB09-69AB92C34660&ext=MOV";
}
我的 WS 签名是这样的:
参数:
- 散列
- 标题
- 说明
-
视频
我在尝试上传视频时遇到问题:
-(void)addVideoRequestToWS { BusinessLogic *bl = [BusinessLogic sharedManager]; ApiClientBlitzApp *client = [ApiClientBlitzApp sharedClient]; NSString *videoURL = [self.videoDictionary objectForKey:@"UIImagePickerControllerReferenceURL"]; NSData *videoData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath: videoURL]]; // I suppose my problem are from two lines of code NSMutableURLRequest *request = [client multipartFormRequestWithMethod:@"POST" path:getAddVideo parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) { [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",bl.currentUser.hash] dataUsingEncoding:NSUTF8StringEncoding] name:@"hash"]; [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.textFieldTitle.text] dataUsingEncoding:NSUTF8StringEncoding] name:@"title"]; [formData appendPartWithFormData:[[NSString stringWithFormat:@"%@",self.textFieldDescription.text]] dataUsingEncoding:NSUTF8StringEncoding] name:@"description"]; [formData appendPartWithFileData:videoData name:@"video_file" fileName:@"testvideo.mov" mimeType:@"video/quicktime"]; }]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) { NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite); }]; [client enqueueHTTPRequestOperation:operation]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { NSData *JSONData = [operation.responseString dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableContainers error:nil]; NSLog(@"jsonObject of the list = %@", jsonObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"error: %@", operation.responseString); NSLog(@"%@",error); }]; [operation start]; }
【问题讨论】:
标签: ios iphone video file-upload afnetworking