此功能将仅发送小视频。如何更改此设置以发送 100 MB 视频?服务器限制设置为 200 MB。上传视频时,我将视频的文件路径发送到 SQL Db,并将具有唯一 ID 的视频发送到文件管理器。如果视频小于 5MB,则返回成功添加的消息,如果视频超过 5MB,则文件管理器中没有视频。我试图得到这个,但我无法解决它。
据我了解,Swift/NSURLSession 不会将大量数据加载到内存中。
有人可以告诉我如何将其转换为工作。
func uploadVideo2 (){
//Bool to control Post Activity Indicator.isHidden
DispatchQueue.main.async(execute: {
self.videoOnOff = "on"
self.postActivityIndicatorIsHidden()
})
//Here we get the card's UUID to be used with the param
let unquieID = theDictionary.value(forKey: "unquieID") as! String
// param to be sent in body. This will be used in the $_request variable in the DBVideo.php
let param = ["videoUnquieID" : unquieID] //This is the card's UUID
// url path to php file
let url = URL(string: "xxxx://xxx.xxxxxxxx.xxx/xxx/DBVideo.php")!
// Adding the url to the request variable
var request = URLRequest(url: url)
// Declare POST method
request.httpMethod = "POST"
// Assign video to videoData variable
let videoData = theDictionary.value(forKey: "theVideo") as! Data
// Creat a UUID for the boundary as a string
let boundary = "Boundary-\(UUID().uuidString)"
//Set the request value to multipart/form-data the boundary is the UUID string
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
request.httpBody = createBodyWithParamsVideo(param, //This is the card's UUID
filePathKey: "file", //The path to the variable $_FILES in the DBVideo.php
imageDataKey: videoData as Data, //The video's data from the card
boundary: boundary) // A unquie ID setup just for the baundary
// launch session
URLSession.shared.dataTask(with: request) { data, response, error in
if response != nil {
}
// get main queue to communicate back to user
DispatchQueue.main.async(execute: {
if error == nil {
do {
// json containes $returnArray from php //converting resonse to NSDictionary
let json = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? NSDictionary
DispatchQueue.main.async(execute: {
self.videoOnOff = "off" //Controls for the Activity indicator
self.postActivityIndicatorIsHidden() //Activity indicator
})
// declare new parseJSON to store json
guard let parseJSON = json else {
print("Error while parsing")
DispatchQueue.main.async(execute: {
self.contactImageOnOff = "off" //Controls for the Activity indicator
self.postActivityIndicatorIsHidden() //Activity indicator
})
return
}
var msg : String!
//getting the json response
msg = parseJSON["message"] as! String?
//printing the response
print(msg)
// error while jsoning
} catch {
let message = error
print(message)
}
// error with php
} else {
//no nothing
}
})
}.resume()
}
这是PHP
<?php
//STEP 1. Check to see if data was passed to this php file
if (empty($_REQUEST['videoUnquieID'])) {
$returnArray["massage"] = "Missing required information";
return;
}
// Pass POST via htmlencryot and assign to $id
$id = htmlentities($_REQUEST['videoUnquieID']);
//STEP 2. Createing the $folder variable to hold the path where the video will be placed
$folder = "VBCVideo/";
//STEP 3. Move uploaded file
$folder = $folder . basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $folder)) {
$returnArray["status"]="200";
$returnArray["message"]="The Video file has been uploaded";
} else {
$returnArray["status"]="300";
$returnArray["message"]="Error while uploading the Video";
}
//STEP 4. Build connection
//Constructor to create connection
function __construct()
{
require_once dirname(__FILE__) . '/Config.php';
require_once dirname(__FILE__) . '/DbConnect.php';
// opening db connection
$db = new DbConnect();
$this->connect = $db->connect();
}
// STEP 5. Feedback array to app user
echo json_encode($returnArray);
?>
php.ini
max_execution_time = 500000;
upload_max filesize = 200000M;
post_max_size = 400000M;
memory_limit = 200000m;