'sending video to server works in simulator but not on the iphone

I want to send video file from my iPhone to sever computer. Although it works well in xcode simulator, but it doesn't work on my iPhone.

This is videoURL from simulator. file:///Users/kang1/Library/Developer/CoreSimulator/Devices/358AB013-E3E3-439E-B262-3E8908A91D52/data/Containers/Data/PluginKitPlugin/A719BBEB-9CFD-4D04-9324-089C970709E8/tmp/trim.ABE9C97D-84F3-4D8D-95C9-58A650D5545D.MOV

And this is videoURL from iPhone. file:///private/var/mobile/Containers/Data/PluginKitPlugin/F72A5C2F-3B45-4C40-AAEB-7DAC95C46EC8/tmp/trim.16B4D9F2-4858-4B86-B43F-E19CE928C3E5.MOV

I think the word "private" in videoURL from iPhone makes impossible to send... If not, please tell me how to make it possible. Please help me. Thanks.

This is my swift code.

var videoURL: URL?

    @IBAction func ButtonClicked(_ sender: UIBarButtonItem) {
        self.navigationController?.popViewController(animated: true)
        do {
            print("videoURL : \(videoURL!)")
            uploadImage(imageURL: videoURL!)
        } catch {
            
        }
    }
}

func uploadImage(imageURL: URL?) {
        
        let URL = "http://127.0.0.1:8000/uploadfiles"
        let header : HTTPHeaders = [
            "Content-Type" : "application/json"]
    
    AF.upload(multipartFormData: { multipartFormData in
        multipartFormData.append(imageURL!, withName: "files", fileName: "video.mp4", mimeType: "video/mp4")
        
    }, to: URL, usingThreshold: UInt64.init(), method: .post, headers: header).response { response in
        guard let statusCode = response.response?.statusCode,
              statusCode == 200
        else { return }
    }
}

extension ViewController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {

        picker.dismiss(animated: true, completion: nil)
        if let pickedVideo = info[UIImagePickerController.InfoKey.mediaURL] as? URL {
            videoURL = pickedVideo
}

ios


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source