iOS - How to upload a video with uploadTask?

后端 未结 3 532
Happy的楠姐
Happy的楠姐 2021-01-16 06:52

I need to upload an mp4 video file from iPhone/iPad to a server, also in the background, so I read that is possible with URLSession.uploadTask(with: URLRequest, from

3条回答
  •  长情又很酷
    2021-01-16 07:28

    Sometimes it is easier for the server to read file from form-data. For instance, the flask framework can read file uploaded in the format of form-data easily by request.files. Alamofire provides an easy way to do this

    AF.upload(multipartFormData: { multipartFormData in
                    multipartFormData.append(FilePath, withName: FilePath.lastPathComponent)
                }, to: url).responseJSON { response in
                        debugPrint(response)
                }
    

    In this way, the file will be uploaded in the format of form-data.

提交回复
热议问题