0

I have a react native app with a webview

import React from 'react';
import {Text, View} from 'react-native';
import {WebView} from 'react-native-webview';

const App = () => {
  return (
    <View style={{flex: 1}}>
      <WebView source={{uri: 'https://websitedomain.invalid/my'}} />
    </View>
  );
};

export default App;

On the page I have a form with a file input, but the request always fails with http code 0, however only inside the webview. The same webpage works fine in the browser

document.getElementById("fileUpload").addEventListener("change", (e) => {
        const formData = new FormData();
        const fileInput = document.getElementById("fileUpload");
        for(let i = 0; i < fileInput.files.length; i++) {
            formData.append(`file${i}`, fileInput.files[i]);
        };
        let xhr = new XMLHttpRequest();
        xhr.open("POST", "https://upload.websitedomain.invalid");
        xhr.setRequestHeader("authentication", "<%=user.uploadKey%>"); // uploadKey is added by ejs
        xhr.onreadystatechange = function() {
            if(xhr.readyState == 4 && xhr.status == 200) {
                        location.reload();
            } else if (xhr.readyState == 4 && xhr.status != 200) {
                alert(`${xhr.status}: ${xhr.responseText}`) // on the webview this says "0: "
            }
        }
        xhr.send(formData);
    })

Is this some sort of Android permissions issue?

Skelly
  • 109
  • 1
  • 10

0 Answers0