react-native-document-picker is just not working

0
64


I implement file uploads in react native however there’s one challenge in console:
enter image description here

const [file, setFile] = useState(null);

  const pickDocument = async () => {
    attempt {
      const res = await DocumentPicker.choose({
        sort: [DocumentPicker.types.allFiles],
      });
      setFile(res);
    } catch (err) {
      if (DocumentPicker.isCancel(err)) {
        console.log('Consumer cancelled the picker');
      } else {
        console.log('DocumentPicker Error: ', err);
      }
    }
  };

  const uploadFile = async () => {
    if (!file) return;

    const formData = new FormData();
    formData.append('information', {
      uri: file.uri,
      identify: file.identify,
      sort: file.sort,
    });

    attempt {
      const response = await axios.publish(
        'http://localhost:1337/api/add',
        formData,
        {
          headers: {
            'Content material-Sort': 'multipart/form-data',
          },
        },
      );

      console.log(response.knowledge);
    } catch (error) {
      console.error(error);
    }
  };

  return (
    <View type={kinds.container}>
      <Textual content>YOUR DOCS</Textual content>
      <Button title="Decide a doc" onPress={pickDocument} />
      {file && <Textual content>{file.identify}</Textual content>}
      <Button title="Add Doc" onPress={uploadFile} />
    </View>
  );
};

the code appears to be proper, imports as properly. I restarted an app. It didn’t assist.
Additionally I linked the dependency, after put in. I might be glad in the event you may also help me !