2017-12-05 33 views
0

안녕하세요, 난 그냥 비디오를 기록하고 비디오 formate mov를 mp4로 변환 NSData 변경 이미지 피커보기를 사용 게시 용. 하지만 그것은 작동하지 않습니다 내가 415 오류를 몇 번 500 오류를 얻을. 구현 방법은 아래 코드를 확인하십시오. 누구든지이 문제를 안내하거나 도와 줄 수 있습니다. 내 서버 측 팀을 확인해야하는 경우내가 게시/업로드하는 방법을 게시/업로드하는 방법을 필요로 서버에 이진 formate 및 mp4 형식을 사용하여 객관적인 C

, 그들은 5 월 어떤 실수가 GUID를 바랍니다 않았다면 내가 당신에게

-(void)camerabuttonHandlerqas{ 

UIAlertController * picker = [UIAlertController alertControllerWithTitle:@"Pick an image using" message:nil preferredStyle:UIAlertControllerStyleActionSheet]; 

UIImagePickerController * imagePicker = [[UIImagePickerController alloc]init]; 
imagePicker.delegate = self; 



UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * action) { }]; 

UIAlertAction* takeVideo = [UIAlertAction actionWithTitle:@"TakeVideo" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) { 
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; 


imagePicker.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil]; 

imagePicker.view.tag = 100; 

[self presentViewController:imagePicker animated:YES completion:nil]; }]; 
[picker addAction:picture]; 

[picker addAction:cancel]; 

picker.view.tintColor = [UIColor grayColor]; 
[self presentViewController:picker animated:YES completion:nil]; 

} 

#pragma mark - <UIImagePickerControllerDelegate> 

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info { 

videoURL = info[UIImagePickerControllerMediaURL]; 

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

NSString* videoPath = [NSString stringWithFormat:@"%@/test_%d.mp4", [paths objectAtIndex:0],arc4random_uniform(1000)]; 

NSURL *outputURL = [NSURL fileURLWithPath:videoPath]; 


[self convertVideoToLowQuailtyWithInputURL:videoURL outputURL:outputURL handler:^(AVAssetExportSession *exportSession) 


{ 



switch (exportSession.status) { 
    case AVAssetExportSessionStatusFailed: 
     NSLog(@"status failed"); 
     break; 
    case AVAssetExportSessionStatusCompleted:{ 
     NSLog(@"status success %@ ",videoPath); 
     NSMutableDictionary *data = [NSMutableDictionary new]; 

     videoURL = info[UIImagePickerControllerMediaURL]; 


     [data setObject:[self generatePostDataForData:[NSData dataWithContentsOfFile:videoPath]] forKey:@"SelectedvideoURL"]; 
     imagePickerIsSelected = YES; 
     [self postData:data]; 
     break; 

    } 

}]; 


[picker dismissViewControllerAnimated:YES completion:nil]; } 
- (NSData *)generatePostDataForData:(NSData *)uploadData 


{ // Generate the post header: 

NSString *post = [NSString stringWithCString:"--AaB03x\r\nContent-Disposition: form-data; name=\"upload[file]\"; 

filename=\"somefile\"\r\nContent-Type: application/octet-stream\r\nContent-Transfer-Encoding: binary\r\n\r\n" encoding:NSASCIIStringEncoding]; 

    // Get the post header int ASCII format: 


NSData *postHeaderData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; 

// Generate the mutable data variable: 


NSMutableData *postData = [[NSMutableData alloc] initWithLength: [postHeaderData length] ]; 
[postData setData:postHeaderData]; 


// Add the image: 
// Add the closing boundry: 





[postData appendData: [@"\r\n--AaB03x--" dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]]; 

// Return the post data: 

return postData; 
} 







-(void) postData:(NSData *)data 

{ 


service = [NSString stringWithFormat:@"http://1.1.1.1:8080/testing/postapi/photoUpload/uploadVideo?videoName=video_%d&type=mp4",arc4random_uniform(1000)] 

delegate = delegateInstance; 
service = [service stringByAddingPercentEncodingWithAllowedCharacters: [NSCharacterSet URLFragmentAllowedCharacterSet]]; 




NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; 

[request setURL:[NSURL URLWithString:service]]; 
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData]; 

[request setHTTPShouldHandleCookies:NO]; 


[request setTimeoutInterval:60]; 


[request setHTTPMethod:@"POST"]; 

// set Content-Type in HTTP header 

[request setValue:@"mp4/MOV" forHTTPHeaderField: @"Content-Type"]; 



NSMutableData *body = [NSMutableData data]; 

// add image data 


if (videoData) { 
    [body appendData:videoData]; 
} 

// setting the body of the post to the reqeust 


[request setHTTPBody:videoData]; 


// set URL 

NSURLSession *session = [NSURLSession sharedSession]; 


NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request 
             completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { 

              if (error) { 
               NSLog(@"%@", error); 
              } else { 
               NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response; 
               NSLog(@"%@", httpResponse); 


} }]; [dataTask resume]; } 

답변

0

감사 나는 그것이 작동하지 않는 코드 아래의 구현입니다 때 잘 작동 우체부와 테스트 415 오류 미디어 유형 오류 NSDATA를 저장하는 서버 데이터 유형을 확인하십시오.

0

나는 코드가 절대적으로 옳으며 서버 측에서 .mov 형식을 허용하고 서버 측과 논의한 다음 내용 유형을 변경해야하는 경우 mp3로 미디어 유형을 변경하지 않아도되고 그 다음 하나의 데이터처럼 파일을 가져 오는 솔루션이 있습니다. 그것의 나를 위해 일

감사합니다.