Search code examples
iosiphoneswiftalamofire

Alamofire upload crashing only on iphone 6s plus


My app uploads photos perfectly with alamofire 4.0.1 on all devices except iphone 6s plus.(tested on iphone 4s,5,5s,6,7,7plus with versions 9.2 and 10.1)

        let image = profileimage
        Alamofire.upload( multipartFormData: { multipartFormData in
                // import image to request
                if let imageData = UIImageJPEGRepresentation(image!, 1) {

                    multipartFormData.append(imageData, withName: "user_profile.profile_picture", fileName: "profile_picture"+NSUUID().uuidString, mimeType: "image/png")
                }      
            },
            usingThreshold: SessionManager.multipartFormDataEncodingMemoryThreshold,
            to:  baseURL+String(currentUser.id)+"/",
            method: .put,
            headers: headers,
            encodingCompletion: { encodingResult in
                switch encodingResult {
                case .success(let upload, _, _):
                    upload.responseJSON { response in
                        let user = createUserFromJSON(response.result.value as! NSDictionary) //crashes here, response is nil
                        completion(user, nil)
                    }
                case .failure(let encodingError):
                    let error = encodingError
                    completion(nil, error)
                }
        })

On iphone 6s plus it crashes with this:

2016-12-02 13:26:04.391264 app[22207:366529] [] nw_socket_get_input_frames recvmsg(fd 14, 1024 bytes): [54] Connection reset by peer
2016-12-02 13:26:04.393678 app[22207:366529] [] nw_endpoint_flow_prepare_output_frames [3.1 52.17.90.251:443 ready socket-flow (satisfied)] Failed to use 1 frames, marking as failed
2016-12-02 13:26:04.394564 app[22207:366529] [] nw_socket_write_close shutdown(14, SHUT_WR): [57] Socket is not connected
2016-12-02 13:26:04.394945 app[22207:366529] [] nw_endpoint_flow_service_writes [3.1 52.17.90.251:443 ready socket-flow (satisfied)] Write request has 0 frame count, 0 byte count
2016-12-02 13:26:04.396875 app[22207:366613] [] __tcp_connection_write_eof_block_invoke Write close callback received error: [89] Operation canceled

Solution

  • This had nothing to do with Alamofire! It was NGINX which had a maximum file upload size. I found out by printing the responseString instead of JSON. It said "Request entity too large".

              upload.responseString { response in
                 print(response.result.value)
                }