I'm trying to upload an existing zip file to a server, but the file itself doesn't seem to be present in the request when I check what the server actually receives. Here's my current implementation:
func uploadZip(filePath: URL, authorization: String, callback: @escaping ((Bool) -> Void)) {
BGUploadManager.callback = callback
let url = URL(string: "\(APINetwork.BASE_URL)")!
var request = URLRequest(url: url)
request.headers = ["Authorization": "Bearer " + authorization]
request.method = HTTPMethod(rawValue: "POST")
request.setValue("application/zip", forHTTPHeaderField: "Content-Type")
let config = URLSessionConfiguration.background(withIdentifier: "identifier")
config.isDiscretionary = false
let session = URLSession(configuration: config, delegate: self, delegateQueue: OperationQueue.main)
let task = session.uploadTask(with: request, fromFile: filePath)
task.resume()
}
There are implemented handlers for completion and progress and they work properly. The problem is really just the actual file not being sent (or if it is I don't know how to get it). Here's parts of what the server receives:
headers:
{ host: 'localhost:1337',
'content-type': 'application/zip',
'accept-encoding': 'gzip, deflate',
connection: 'keep-alive',
accept: '*/*',
'user-agent': 'App/37 CFNetwork/1237 Darwin/20.4.0',
authorization:
'Bearer sometokenhere',
'content-length': '89634' }
body: {}
Checking for request.files also shows that it's empty. The Content-Length value is correct. The filePath is the full path and does actually point to the zip file.