菜鸟教程小白 发表于 2022-12-11 18:14:40

ios - Alamofire 上传仅在 iphone 6s plus 上崩溃


                                            <p><p>我的应用使用 alamofire 4.0.1 在除 iphone 6s plus 之外的所有设备上完美上传照片。(在 iphone 4s、5、5s、6、7、7plus 版本 9.2 和 10.1 上测试)</p>

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

                  multipartFormData.append(imageData, withName: &#34;user_profile.profile_picture&#34;, fileName: &#34;profile_picture&#34;+NSUUID().uuidString, mimeType: &#34;image/png&#34;)
                }      
            },
            usingThreshold: SessionManager.multipartFormDataEncodingMemoryThreshold,
            to:baseURL+String(currentUser.id)+&#34;/&#34;,
            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)
                }
      })
</code></pre>

<p>在 iphone 6s plus 上它崩溃了:</p>

<pre><code>2016-12-02 13:26:04.391264 app [] nw_socket_get_input_frames recvmsg(fd 14, 1024 bytes): Connection reset by peer
2016-12-02 13:26:04.393678 app [] nw_endpoint_flow_prepare_output_frames Failed to use 1 frames, marking as failed
2016-12-02 13:26:04.394564 app [] nw_socket_write_close shutdown(14, SHUT_WR): Socket is not connected
2016-12-02 13:26:04.394945 app [] nw_endpoint_flow_service_writes Write request has 0 frame count, 0 byte count
2016-12-02 13:26:04.396875 app [] __tcp_connection_write_eof_block_invoke Write close callback received error: Operation canceled
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>这与 Alamofire 无关!具有最大文件上传大小的是 NGINX。我是通过打印 responseString 而不是 JSON 发现的。它说“请求实体太大”。</p>

<pre><code>          upload.responseString { response in
             print(response.result.value)
            }
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - Alamofire 上传仅在 iphone 6s plus 上崩溃,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/40932482/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/40932482/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - Alamofire 上传仅在 iphone 6s plus 上崩溃