Faced such a problem: when I send more than 3 post images to the server with a request, my data is not sent, more precisely, empty data is sent. And if the number of images <= 3, then the request is sent. I can not understand what the problem is: in the number of images or in the size of the data sent. If in the second, is there a limit on the size of the data sent by the post request in swift ? Does anyone have a sample code in which more than 3 images are sent to the server?
Here is an example code where I send data to the server:
func uploadFile( request sourceRequest: NSMutableURLRequest){ sourceRequest.httpMethod="POST" let boundary = "FileUploader-boundary-\(arc4random())-\(arc4random())" sourceRequest.setValue( "multipart/form-data;boundary=\(boundary)", forHTTPHeaderField: "Content-Type") let data = NSMutableData() for (name, value) in headers { sourceRequest.setValue(value, forHTTPHeaderField: name) } // Amazon S3 (probably others) wont take parameters after files, so we put them first for (key, value) in parameters { data.append("\r\n--\(boundary)\r\n".data(using: String.Encoding.utf8)!) data.append("Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n\(value)".data(using: String.Encoding.utf8)!) } for fileUploadInfo in files { data.append( "\r\n--\(boundary)\r\n".data(using: String.Encoding.utf8)! ) data.append( "Content-Disposition: form-data; name=\"\(fileUploadInfo.name)\"; filename=\"\(fileUploadInfo.fileName)\"\r\n".data(using: String.Encoding.utf8)!) data.append( "Content-Type: \(fileUploadInfo.mimeType)\r\n\r\n".data(using: String.Encoding.utf8)!) if fileUploadInfo.data != nil { data.append( fileUploadInfo.data! as Data ) } else if fileUploadInfo.url != nil, let fileData = NSData(contentsOf: fileUploadInfo.url! as URL) { data.append( fileData as Data ) } else { // ToDo: report error print("error") } } data.append("\r\n--\(boundary)--\r\n".data(using: String.Encoding.utf8)!) sourceRequest.httpBody=data as Data let task=URLSession.shared.dataTask(with: sourceRequest as URLRequest, completionHandler: { (data:Data?,response:URLResponse?,error:Error?) in if error==nil{ let responseString = String(data: data!, encoding: .utf8) print(responseString!) }else{ print(error?.localizedDescription) } }) task.resume() // Alamofire.upload(data as Data, with: request as URLRequest).responseString{ // response in // if response.result.error == nil { // print(response) // }else{ // print(response.result.error!) // } // } }