0

I am trying to upload video and image on server in swift using Json and php. I am uploading both image and video with some more parameters. I am able to upload image on server but not to upload video.

 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()
}

and the php file

<?php
if (move_uploaded_file($_FILES['file']['tmp_name'], "image.png")) {
echo "File uploaded: ".$_FILES["file"]["name"];
} 

can anyone teach me for video upload. thanks

DQueen
  • 9
  • 1
  • 6

1 Answers1

0

what's the difference between image and video? they are both binary data. the possible reason may be a php restriction on uploaded file size.; Look at this manual and your php.ini as well. There must be the lines

Maximum allowed size for uploaded files.
upload_max_filesize = 10M

; Must be greater than or equal to upload_max_filesize
post_max_size = 10M
heximal
  • 10,327
  • 5
  • 46
  • 69
  • my problem lies in programming function to upload video on the swift , can you explain me how to upload videos , I mean the function which was formed in swift using xcode. Im new in swift . thanks about the restriction size in php – DQueen Apr 19 '16 at 09:56