0
請使用HTTP post方法將我寫入的代碼發送到服務器,以處理它。通過iOS中的http post方法發送到服務器的視頻
服務器被擊中,但響應正顯示出空,我不明白什麼會出錯
- (IBAction)choose:(id)sender {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
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)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
if ([type isEqualToString:(NSString *)kUTTypeVideo] ||
[type isEqualToString:(NSString *)kUTTypeMovie])
{
self.videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
- (IBAction)upload:(id)sender {
//NSString * str = @"content";
// [str stringByAppendingString:self.url];
NSMutableURLRequest *request = [[AFHTTPRequestSerializer serializer] multipartFormRequestWithMethod:@"POST" URLString:@"http://mobile.supportservice.co.in/bbgapp.asmx/Stream" parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//NSString * str = [[NSBundle mainBundle] pathForResource:@"amyVideo" ofType:@"png"];
NSLog(@"------------------>%@",self.videoURL);
[formData appendPartWithFileURL:[NSURL fileURLWithPath:self.videoURL] name:@"file" fileName:@"myVideo.m4v" mimeType:@"mp4/m4v" error:nil];
} error:nil];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
NSURLSessionUploadTask *uploadTask;
uploadTask = [manager
uploadTaskWithStreamedRequest:request
progress:^(NSProgress * _Nonnull uploadProgress) {
// This is not called back on the main queue.
// You are responsible for dispatching to the main queue for UI updates
dispatch_async(dispatch_get_main_queue(), ^{
//Update the progress view
[self.progressView setProgress:uploadProgress.fractionCompleted];
});
}
completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) {
if (error) {
NSLog(@"Error: %@", error);
} else {
NSLog(@"----------------------> %@ %@", response, responseObject);
}
}];
[uploadTask resume];
}
@end
這裏是我的output
它爲我工作了一個小小的改變,謝謝! –