这是我的尝试:
- (IBAction)takeVideoUIButton *)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
[self presentViewController:picker animated:YES completion:NULL];
}
- (void)imagePickerControllerUIImagePickerController *)picker didFinishPickingMediaWithInfoNSDictionary *)info {
self.movieURL = info[UIImagePickerControllerMediaURL];
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)imagePickerControllerDidCancelUIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (void)viewDidAppearBOOL)animated {
self.movieController = [[MPMoviePlayerController alloc] init];
self.movieController.controlStyle = MPMovieControlStyleNone;
[self.movieController setContentURL:self.movieURL];
[self.movieController.view setFrame:CGRectMake (15, 125, 292, 390)];
self.movieController.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.movieController.view];
[self.movieController play];
NSString *myString = [self.movieURL absoluteString];
//THE DATA IS RETURNING 0 :
NSData *videoData = [NSData dataWithContentsOfFile:myString];
NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:videoData.length countStyle:NSByteCountFormatterCountStyleFile]);
[self setImageDataToSend:videoData];
}
- (void)moviePlayBackDidFinishNSNotification *)notification {
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.movieController stop];
[self.movieController.view removeFromSuperview];
self.movieController = nil;
}
我没有收到来自 URL 的任何数据?
-(IBAction)uploadvideotowebsiteid)sender{
//you can use any string instead "com.mycompany.myqueue"
dispatch_queue_t backgroundQueue = dispatch_queue_create("com.mcompany.myqueue", 0);
//turn on
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
dispatch_async(backgroundQueue, ^{
PFUser *user = [PFUser currentUser];
NSString * url = [NSString stringWithFormat"http://******.co.uk/****/imageupload.php"];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod"OST"];
NSString *boundary = @"---------------------------14737809831466499882746641449";
NSMutableData *body = [[NSMutableData alloc]init];
[body appendData:[[NSString stringWithFormat"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
NSString *String = @"Content-Disposition: form-data; name=\"image\"; filename=\"";
NSString *String2 = @"video";
NSString *String3 = @".MOV\"\r\n";
NSString *connection1 = [String stringByAppendingString: String2];
NSString *done = [connection1 stringByAppendingString: String3];
[body appendData:[[NSString stringWithFormat:done] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: audio/basic\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:_imageDataToSend];
[body appendData:[[NSString stringWithFormat"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:body];
NSString *contentType = [NSString stringWithFormat"multipart/form-data; boundary=%@",boundary];
[request addValue:contentType forHTTPHeaderField: @"Content-Type"];
//Send the Request
NSData* returnData = [NSURLConnection sendSynchronousRequest: request
returningResponse: nil error: nil];
//serialize to JSON
if (!returnData){
return; // or handle no connection error here
}else{
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:returnData options:NSJSONReadingMutableContainers error:nil];
//parsing JSON
bool success = [result[@"success"] boolValue];
if(success){
NSLog(@"Success=%@",result[@"msg"]);
//[self performSegueWithIdentifier"toshow" sender:self];
}else{
NSLog(@"Fail=%@",result[@"msg"]);
}
}
dispatch_async(dispatch_get_main_queue(), ^{
//turn off
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
});
});
}
我没有收到任何错误。但是我在我的网站上收到了一个大小为 0kb 的文件。
谁能解释为什么我没有从视频中获得任何数据?
当然,这是你的错误:
NSString *myString = [self.movieURL absoluteString];
应该是路径
NSString *myString = [self.movieURL path];
NSData *videoData = [NSData dataWithContentsOfFile:myString];
NSLog(@"%@",[NSByteCountFormatter stringFromByteCount:videoData.length countStyle:NSByteCountFormatterCountStyleFile]);
关于ios - 通过http上传视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23343491/
欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) | Powered by Discuz! X3.4 |