gpt4 book ai didi

ios - 如何在 Swift 中将视频和图像上传到服务器上

转载 作者:行者123 更新时间:2023-11-30 13:29:55 28 4
gpt4 key购买 nike

我正在尝试使用 Json 和 php 在服务器上快速上传视频和图像。我正在上传带有更多参数的图像和视频。我可以在服务器上上传图像,但不能上传视频。

 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 对上传文件大小的限制。看this manual还有你的 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

关于ios - 如何在 Swift 中将视频和图像上传到服务器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36688111/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com