Я проследил весь процесс в данном документе, но все равно я получаю ошибку ниже на обеих платформах:
по ссылке : https://www.npmjs.com/package/react-native-document-picker
console.error: "undefined не является объектом (оценка
Ошибка _reactNativeDocumentPicker.DocumentPicker.show))
index.delta?platform=android&dev=true&minify=false:57115:29 вложение
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
index.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: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);
})
}
});
}