I am trying to send a file (png, doc, jpg, etc...) to my server. However for me to save the file properly I'd like to add the file extension to my POST request. Apple.developer says "The body stream and body data in this request object are ignored." Is there a way to add body data to my request? Here's what I have so far:
func uploadFile(filePath: String, endpoint: String) -> Void {
let session = URLSession.shared
let url = URL(string: endpoint)!
var request = URLRequest(url: url)
request.httpMethod = "POST"
let fileUrl = URL(fileURLWithPath: filePath)
let task = session.uploadTask(with: request, fromFile: fileUrl)
task.resume()
}
I tried to switch to using uploadTask(with:data:) but I am not sure how to add a file to data since most examples are using image