1

I've tried following https://stackoverflow.com/a/40714217/9957948 and https://stackoverflow.com/a/35206069/9957948 with no success. I am still getting Network request failed.

Here is my cURL request that works:

curl -X POST "url" -H  "Content-Type: multipart/form-data; boundary=--CUSTOM" -H "Content-Length: 237" -d $'----CUSTOM\nContent-Disposition: form-data; name="fileToUpload"; filename="t006"\nContent-Type: application/octet-stream\n\nset shiftwidth=4\nset autoindent\n\n----CUSTOM\nContent-Disposition: form-data; name="submit"\n\nUpload Image\n----CUSTOM--\n'

And here is what I tried to convert it to, and it is returning Network request failed.

uploadFile(){
        const formData = new FormData()
        formData.append('blob', new Blob(['set shiftwidth=4\nset autoindent\n']), 't006')

        fetch('url', {
          method: 'POST',
          body: formData
        })
        .then(data => {
          console.log(data)
        })
        .catch(error => {
            console.log('error:' + error.message);
        })

Is Content-Length or the body Content-Type: application/octet-stream required?

I'm fairly new to all this so any help would be appreciated. Thanks

microflakes
  • 313
  • 2
  • 10
  • it's hard for me to reproduce your example. do you have a working `url` I could use? – richytong May 28 '20 at 17:43
  • What does the Network tab in the browser's developer tools show? Is it making the request you expect? Are there any other error messages reported on the Console? (It it perhaps failing with a preflight OPTIONS request?) – Quentin May 28 '20 at 20:00

1 Answers1

-1

Try to use PUT instead of POST method. Add FLIPPER_VERSION=0.41.0 in your gradle.properties. If this does not work then comment a code from ReactNativeFlipper.java class path to this file yourProject\node_modules\react-native\ReactAndroid\src\debug\java\com\facebook\flipper. comment this code path to this file yourProject\node_modules\react-native\ReactAndroid\src\debug\java\com\facebook\flipper