How to Upload Large Video Files in Objective-C

Asked 2 years ago, Updated 2 years ago, 44 views

The iPhone app implements the function of uploading videos to the server.
I succeeded in uploading the video using AFNetworking, but
If the capacity of the video increases, it seems to fail.
Specifically, if the capacity exceeds 10MB, it always fails.

If you want to upload such a large file, click
Is it better to find another way instead of using AFNetworking?
Please let me know if you know more.

·Objective-C

// Get video
NSSstring*dir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents";
NSSstring* path = [dir stringByAppendingPathComponent:@"test.mov";
NSData* videoData=[NSDataDataWithContentsOfURL:[NSURL fileURLWithPath:path]];

// Upload Video
AFHTTPRequestOperationManager*manager = AFHTTPRequestOperationManager manager;
manager.responseSerializer = AFHTTPResponseSerializer;
[manager.requestSerializer setTimeoutInterval:50];

[manager POST:@"(omitted)/deployMovieTest.php" parameters:nil constructionBodyWithBlock:^(id<AFMultipartFormData>formData){
    [formData appendPartWithFileData:videoDataname:@"movie"fileName:@"test.mov"mimeType:@"video/quicktime";
} success:^(AFHTTPRequestOperation* operation, id responseObject) {
    NSLog(@"Success: Show JSON %@", responseObject);
    NSSstring* responseStr = [[NSSstring alloc] initWithData: responseObject encoding:NSUTF8 StringEncoding];
    NSLog(@"Success: Display characters %@",responseStr);
} failure:^(AFHTTPRequestOperation*operation, NSError*error){
    NSLog(@"Failure:%@", error);
}];

·php

<?php

// Information received at POST is in $_FILES.
// Receive video at POST.
$image=file_get_contents($_FILES['movie']['tmp_name']);


// Created the destination URL to be moved.
$uploaddir='(omitted)/uploads/';
$uploadfile=$uploaddir.basename($_FILES['movie']['name']);

// Saved the file.
$message="";
if(move_uploaded_file($_FILES['movie']['tmp_name'], $uploadfile)){
    $message="OK!\n";
} else{
    $message="NO:)";
}

// output
header('Content-type:application/json');
echo json_encode($message);

?>

php objective-c

2022-09-30 10:52

1 Answers

コメント I solved the problem by commenting, but I will also write it down in the person who answered.I would like to ask the viewer to approve this answer as they know that it has been resolved.

The server said PHP, so I tried to estimate the cause.
In php, the php.ini setting has a "upload_max_filesize" setting, which limits the size of the file to upload.This value must be set to the maximum expected value of the file you want to upload (the specified value is set to a smaller value such as 2M or 10M).


2022-09-30 10:52

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.