Ios 如何在Swift中在服务器上上传视频和图像
我正在尝试使用Json和php在服务器上用swift上传视频和图像。我上传的图像和视频与一些更多的参数。我可以上传服务器上的图像,但不能上传视频Ios 如何在Swift中在服务器上上传视频和图像,ios,xcode,swift,Ios,Xcode,Swift,我正在尝试使用Json和php在服务器上用swift上传视频和图像。我上传的图像和视频与一些更多的参数。我可以上传服务器上的图像,但不能上传视频 func myImageUploadRequest(){ let myUrl = NSURL(string: "http://192.168.3.52/cobaupload2/index.php"); let request = NSMutableURLRequest(URL:myUrl!); request.HTTPMet
func myImageUploadRequest(){
let myUrl = NSURL(string: "http://192.168.3.52/cobaupload2/index.php");
let request = NSMutableURLRequest(URL:myUrl!);
request.HTTPMethod = "POST";
let param = [
"firstName" : "TESTNAME",
"lastName" : "TESTNAMELAST",
"userId" : "10"
]
let boundary = generateBoundaryString()
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
let imageData = UIImageJPEGRepresentation(myImageView.image!, 1)
if(imageData==nil) { return; }
request.HTTPBody = createBodyWithParameters(param, filePathKey: "file", imageDataKey: imageData!, boundary: boundary)
myActivityIndicator.startAnimating();
let task = NSURLSession.sharedSession().dataTaskWithRequest(request) {
data, response, error in
if error != nil {
print("error=\(error)", terminator: "")
return
}
print("******* response = \(response)", terminator: "")
let responseString = NSString(data: data!, encoding: NSUTF8StringEncoding)
print("****** response data = \(responseString!)")
//let json:NSDictionary = (try! NSJSONSerialization.JSONObjectWithData(data!, options:NSJSONReadingOptions.MutableContainers )) as! NSDictionary
dispatch_async(dispatch_get_main_queue(),{
self.myActivityIndicator.stopAnimating()
self.myImageView.image = nil;
});
}
task.resume()
}
和php文件
<?php
if (move_uploaded_file($_FILES['file']['tmp_name'], "image.png")) {
echo "File uploaded: ".$_FILES["file"]["name"];
}
图像和视频的区别是什么?它们都是二进制数据。可能的原因可能是php对上传文件大小的限制。; 请同时查看和您的php.ini。一定有台词
Maximum allowed size for uploaded files.
upload_max_filesize = 10M
; Must be greater than or equal to upload_max_filesize
post_max_size = 10M
你可以上传你的图像,参数如下:我已经完成了图像上传,我发布了函数源代码,现在正在寻找视频上传@Fatihyildizhan我的问题在于在swift上上传视频的编程功能,你能告诉我如何上传视频吗,我指的是使用xcode在swift中形成的函数。我是斯威夫特的新手。感谢php中的大小限制