I wrote pictures before and uploaded the PHP server. Today I changed the interface slightly and posted the code for uploading the video. The upload function has been adjusted at present, and the compressed code of the video seems to be incomplete. The compressed part of the code will be improved in the future;
- (void)convertVideoWithURL:(NSURL *)url { NSDate *date = [NSDate date]; NSDateFormatter *dateformatter = [[NSDateFormatter alloc]init]; [dateformatter setDateFormat:@"YYYY-MM-dd-HH-mm-ss"]; NSString *dateName = [dateformatter stringFromDate:date]; NSString *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject; NSString *pathName = [path stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.mp4",dateName]]; NSLog(@"Sandbox: %@",pathName); //Transcoding configuration AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil]; AVAssetExportSession *exportSession= [[AVAssetExportSession alloc] initWithAsset:asset presetName:AVAssetExportPresetMediumQuality]; = YES; = [NSURL fileURLWithPath:pathName]; = AVFileTypeMPEG4; [exportSession exportAsynchronouslyWithCompletionHandler:^{ int exportStatus = ; switch (exportStatus) { case AVAssetExportSessionStatusFailed: { // log error to text view NSError *exportError = ; NSLog (@"AVAssetExportSessionStatusFailed: %@", exportError); [SVProgressHUD showErrorWithStatus:@"Video compression failed"]; [SVProgressHUD dismissWithDelay:1.0]; break; } case AVAssetExportSessionStatusCompleted: { = [NSData dataWithContentsOfFile:pathName]; [[NetTool shareDL]upLoadVideoWithURL:@"http://192.168.1.102/php/" paremeter:nil data: videoName:[NSString stringWithFormat:@"%@.mp4",dateName] progress:^(NSProgress * _Nonnull uploadProgress) { [SVProgressHUD showProgress:1.0*/ status:@"Uploading"]; NSLog(@"Uploading %f%%",(1.0*/)*100); } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { [SVProgressHUD showSuccessWithStatus:@"Uploaded successfully"]; [SVProgressHUD dismissWithDelay:1.0]; } fail:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { [SVProgressHUD showErrorWithStatus:@"Upload failed"]; [SVProgressHUD dismissWithDelay:1.0]; }]; } } }]; }
[manager POST:url parameters:parameter constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { [formData appendPartWithFileData:videoData name:@"upimage" fileName:videoName mimeType:@"video/mp4"]; } progress:^(NSProgress * _Nonnull uploadProgress) { progress(uploadProgress); } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) { success(task,responseObject); } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { fail(task,error); }];
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.