joltup / rn-fetch-blob

A project committed to making file access and data transfer easier, efficient for React Native developers.
MIT License
2.81k stars 772 forks source link

iOS: RNFetch.fetch upload file [The network connection was lost ] #638

Closed QAZDER closed 3 years ago

QAZDER commented 3 years ago

Hi, when using RNFetch.fetch to upload images which selected by react-native-image-picke, it got an error on ios: The network connection was lost. it works fine on android.

is there any config i didn't add to header? thanks in advance!

here is my code:

  const header = {
    Authorization: 'Bearer ' + window.token,
    'Content-Type': 'multipart/form-data'
  }; 

  const bodyData = [{
    name: 'file',
    filename: item.fileDesc || item.fileName,
    data: RNFetchBlob.wrap(item.uri)
  }];

 return (RNFetchBlob.fetch('POST', uploadUrl, header, bodyData));

Version:

    "react": "16.8.6",
    "react-native": "0.60.4",
    "rn-fetch-blob": "^0.12.0",
XCode Log 2020-08-04 13:30:03.115101+0800 XXX[70713:34342226] [] nw_socket_handle_socket_event [C25.1:2] Socket SO_ERROR [54: Connection reset by peer] 2020-08-04 13:30:03.115550+0800 XXX[70713:34342226] [] nw_read_request_report [C25] Receive failed with error "Connection reset by peer" 2020-08-04 13:30:03.115980+0800 XXX[70713:34342226] [] nw_socket_output_finished [C25.1:2] shutdown(26, SHUT_WR) [57: Socket is not connected] 2020-08-04 13:30:03.121374+0800 XXX[70713:34342226] Task <2FD0F2E3-80B4-4312-80D6-4C29B512ADE4>.<1> HTTP load failed, 231630/50 bytes (error code: -1005 [4:-4]) 2020-08-04 13:30:03.124174+0800 XXX[70713:34342226] Task <2FD0F2E3-80B4-4312-80D6-4C29B512ADE4>.<1> finished with error [-1005] Error Domain=NSURLErrorDomain Code=-1005 "The network connection was lost." UserInfo={_kCFStreamErrorCodeKey=-4, NSUnderlyingError=0x600002a1c120 {Error Domain=kCFErrorDomainCFNetwork Code=-1005 "(null)" UserInfo={NSErrorPeerAddressKey={length = 16, capacity = 16, bytes = 0x10021f90c0a80a400000000000000000}, _kCFStreamErrorCodeKey=-4, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <2FD0F2E3-80B4-4312-80D6-4C29B512ADE4>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <2FD0F2E3-80B4-4312-80D6-4C29B512ADE4>.<1>" ), NSLocalizedDescription=The network connection was lost., NSErrorFailingURLStringKey=XXX, NSErrorFailingURLKey=XXX, _kCFStreamErrorDomainKey=4
justinmchase commented 3 years ago

Well its returning a promise, so you should probably have RNFetchBlob.fetch(...).then(...) or use async/await. If you're not awaiting the promise its possible that it never does its work properly without an await.

QAZDER commented 3 years ago

Thanks for the reply. But I don't think this error is caused by async/await cause this error only happens when bodydata is an array, while it works fine when bodydata is an object.

QAZDER commented 3 years ago

finally solved

Sid-Turner-Ellis commented 1 year ago

@QAZDER what was the solution?