首页 > 解决方案 > 无法实现(react-native-document-picker)

问题描述

我已遵循给定文档中的所有流程,但在两个平台上仍然出现以下错误:

以下链接https ://www.npmjs.com/package/react-native-document-picker

console.error: "undefined is not an object (evaluateing '_reactNativeDocumentPicker.DocumentPicker.show')" error index.delta?platform=android&dev=true&minify=false:57115:29 attachment index.delta?platform=android&dev=true&minify=false: 101355:24 onPress index.delta?platform=android&dev=true&minify=false:101392:36 touchableHandlePress index.delta?platform=android&dev=true&minify=false:42176:47 _performSideEffectsForTransition index.delta?platform=android&dev=true&minify=false:15001: 36 _receiveSignal index.delta?platform=android&dev=true&minify=false:14930:46 touchableHandleResponderRelease index.delta?platform=android&dev=true&minify=false:14815:26 invokeGuardedCallback index.delta?platform=android&dev=true&minify=false:15268:21 invokeGuardedCallback index.delta?platform=android&dev=true&minify=false:15337:40 invokeGuardedCallbackAndCatchFirstError index.delta?platform=android&dev=true&minify=false:15340:54 executeDispatch index.delta?platform=android&dev=true&minify=false:15498:64 executeDispatchesInOrder index.delta?platform=android&dev=true&minify=false:15518:26 executeDispatchesAndRelease index.delta?platform=android&dev=true&minify=false:15613:35 executeDispatchesAndReleaseTopLevel index.delta?platform=android&dev=true&minify=false:15626:43 forEachAccumulated 索引。 delta?platform=android&dev=true&minify=false:15603:22 runEventsInBatch index.delta?platform=android&dev=true&minify=false:15714:29 runExtractedEventsInBatch index.delta?platform=android&dev=true&minify=false:15723:25 index.delta?platform=android&dev=true&minify=false:16723:36 batchedUpdates$1 index.delta?platform=android&dev=true&minify=false:25008:20 batchedUpdates index.delta?platform=android&dev=true&minify= false:16663:33 _receiveRootNodeIDEvent index.delta?platform=android&dev=true&minify=false:16722:23 receiveTouches index.delta?platform=android&dev=true&minify=false:16752:34 __callFunction index.delta?platform=android&dev=true&minify=false: 2593:49 index.delta?platform=android&dev=true&minify=false:2370:31 __guard index.delta?platform=android&dev=true&minify=false:2546:15 callFunctionReturnFlushedQueue index.delta?platform=android&dev=true&minify=false:2369:21minify=false:16723:36 batchedUpdates$1 index.delta?platform=android&dev=true&minify=false:25008:20 batchedUpdates index.delta?platform=android&dev=true&minify=false:16663:33 _receiveRootNodeIDEvent index.delta?platform=android&dev=true&minify =false:16722:23 receiveTouches index.delta?platform=android&dev=true&minify=false:16752:34 __callFunction index.delta?platform=android&dev=true&minify=false:2593:49 index.delta?platform=android&dev=true&minify=false: 2370:31 __guard index.delta?platform=android&dev=true&minify=false:2546:15 callFunctionReturnFlushedQueue index.delta?platform=android&dev=true&minify=false:2369:21minify=false:16723:36 batchedUpdates$1 index.delta?platform=android&dev=true&minify=false:25008:20 batchedUpdates index.delta?platform=android&dev=true&minify=false:16663:33 _receiveRootNodeIDEvent index.delta?platform=android&dev=true&minify =false:16722:23 receiveTouches index.delta?platform=android&dev=true&minify=false:16752:34 __callFunction index.delta?platform=android&dev=true&minify=false:2593:49 index.delta?platform=android&dev=true&minify=false: 2370:31 __guard index.delta?platform=android&dev=true&minify=false:2546:15 callFunctionReturnFlushedQueue index.delta?platform=android&dev=true&minify=false:2369:21delta?platform=android&dev=true&minify=false:16663:33 _receiveRootNodeIDEvent index.delta?platform=android&dev=true&minify=false:16722:23 receiveTouches index.delta?platform=android&dev=true&minify=false:16752:34 __callFunction index.delta? platform=android&dev=true&minify=false:2593:49 index.delta?platform=android&dev=true&minify=false:2370:31 __guard index.delta?platform=android&dev=true&minify=false:2546:15 callFunctionReturnFlushedQueue index.delta?platform=android&dev =真&缩小=假:2369:21delta?platform=android&dev=true&minify=false:16663:33 _receiveRootNodeIDEvent index.delta?platform=android&dev=true&minify=false:16722:23 receiveTouches index.delta?platform=android&dev=true&minify=false:16752:34 __callFunction index.delta? platform=android&dev=true&minify=false:2593:49 index.delta?platform=android&dev=true&minify=false:2370:31 __guard index.delta?platform=android&dev=true&minify=false:2546:15 callFunctionReturnFlushedQueue index.delta?platform=android&dev =真&缩小=假:2369:21minify=false:2593:49 index.delta?platform=android&dev=true&minify=false:2370:31 __guard index.delta?platform=android&dev=true&minify=false:2546:15 callFunctionReturnFlushedQueue index.delta?platform=android&dev=true&minify=false :2369:21minify=false:2593:49 index.delta?platform=android&dev=true&minify=false:2370:31 __guard index.delta?platform=android&dev=true&minify=false:2546:15 callFunctionReturnFlushedQueue index.delta?platform=android&dev=true&minify=false :2369:21

使用的代码:

import { DocumentPicker, DocumentPickerUtil } from 'react-native-document-picker';

// iPhone/Android
attachment = () => {
        DocumentPicker.show({
            filetype: [DocumentPickerUtil.allFiles()],
        }, (error, res) => {
            this.setState({ ImageLoad: true })
            console.log(res, 'res data');
            if (res && res.uri) {
                var formData = new FormData();
                formData.append('messagefile', { name: res.fileName, uri: res.uri, type: res.type });
                console.log("form data : ", formData);
                console.log("API Uplod file : ", LOCAL_URL + '/api/uploadChatFiles')
                fetch(LOCAL_URL + '/api/uploadChatFiles', {
                    method: 'POST',
                    headers: {
                        Accept: 'application/json',
                        'Content-Type': 'multipart/form-data',
                    },
                    body: formData,
                }).then((response) => response.json())
                    .then((responseJson) => {
                        this.setState({ ImageLoad: false });
                        console.log('responseJson file name: ', JSON.stringify(responseJson.data.fieldname));
                        console.log('responseJson : ', JSON.stringify(responseJson));
                        if (responseJson.code === 200) {
                            this.setState({ visibleModal: null })
                        }

                        let message = {
                            text: responseJson.data.originalname,
                            from: this.props.senderId,
                            to: this.props.reciverId,
                            isFile: "1"
                        }

                        let messageJson = {
                            message: message,
                            to: this.props.reciverId,
                        }
                        this.socket.emit('message', messageJson);
                        this._storeMessages(message);

                    })
            }
        });
}

标签: reactjsreact-nativedocumentpicker

解决方案


推荐阅读