Network error when sending PDF from Document Picker with FormData

I’m running into a Network error when I try to upload a PDF that was selected through Document Picker. The PDF is sent as Form Data with Axios. This issue only occurs on Android (SDK 42) and only with documents from Document Picker. Images are all working fine using ImagePicker as well. My code for this was working fine for months then after upgrading to SDK 42 it is now failing with no changes from my end. If I submit an image from ImagePicker it works correctly but if I select the same image through DocumentPicker it fails. I also noticed the uri returned from Document Picker on Android only does not include the leading “file://”, not sure if that causes any problems. I have tried appending the missing “file://” to the uri but that doesn’t seem to do anything.

Below is the error I am receiving:

{
  "message": "Network Error",
  "name": "Error",
  "stack": "createError@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:241425:26\nhandleError@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:241335:27\ndispatchEvent@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:33389:31\nsetReadyState@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:32554:33\n__didCompleteResponse@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:32370:29\nemit@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:4020:42\n__callFunction@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:3204:36\nhttp://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:2936:31\n__guard@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:3158:15\ncallFunctionReturnFlushedQueue@http://192.168.50.79:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:2935:21\ncallFunctionReturnFlushedQueue@[native code]",
  "config": {
    "url": "https://53c2-24-71-244-159.ngrok.io/submit",
    "method": "post",
    "data": {
      "_parts": [
        [
          "amount",
          0.06
        ],
        [
          "serviceDate",
          1631170800
        ],
        [
          "doc",
          {
            "size": 680351,
            "name": "testing.pdf",
            "uri": "/data/user/0/host.exp.exponent/cache/ExperienceData/%40myapp%2Fmyapp/DocumentPicker/74cc1ce0-eb40-42ee-9350-839b6c44fd95.pdf",
            "type": "application/pdf"
          }
        ]
      ]
    },
    "headers": {
      "Accept": "application/json, text/plain, */*",
      "Authorization": "JSON-WEB-TOKEN-HERE",
      "Content-Type": "multipart/form-data"
    },
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "timeout": 0,
    "xsrfCookieName": "XSRF-TOKEN",
    "xsrfHeaderName": "X-XSRF-TOKEN",
    "maxContentLength": -1,
    "maxBodyLength": -1,
    "transitional": {
      "silentJSONParsing": true,
      "forcedJSONParsing": true,
      "clarifyTimeoutError": false
    }
  }
}
1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.