我在android中使用react native来开发。我想上传文件或照片到服务器。我使用react-native-file-uploader,我收到了错误:
[undefined不是一个对象(评估 ' _reactNative.NativeModules.FileUploader.upload&#39)],Cannot read property 'upload' of undefined 2
请帮忙,谢谢! 吼叫是我的代码:
import React from 'react';
import {
View,
Text,
Image,
StyleSheet,
TouchableOpacity,
Platform,
DeviceEventEmitter
} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome'
import FileUploader from 'react-native-file-uploader'
const settings = {
/* uri,
uploadUrl,
method, // default to 'POST'
fileName, // default to 'yyyyMMddhhmmss.xxx'
fieldName, // default to 'file'
contentType, // default to 'application/octet-stream'
data: {
// extra fields to send in the multipart payload
}*/
};
export default class NewDishView extends React.Component{
constructor(props){
super(props)
this.state={
avatarSource:'./src/images/support.png'
}
}
goBack(){
this.props.navigator.pop();
}
render(){
return (
<View>
<View style={styles.header}>
<TouchableOpacity onPress={()=>this.goBack()} style={styles.back}>
<Icon style={styles.backIcon} name="chevron-left" />
</TouchableOpacity>
<View style={{flex:1}}>
<Text style={styles.title}>Create new dish</Text>
</View>
</View>
<TouchableOpacity onPress={
FileUploader.upload(settings, (err, res) => {
// handle result
}, (sent, expectedToSend) => {
// handle progress
})
}>
<Text>upload</Text>
</TouchableOpacity>
</View>
)
}
}
const styles = StyleSheet.create({
header:{
flexDirection:'row',
},
back:{
paddingLeft:10,
paddingTop:5,
width:25,
},
backIcon:{
color:'#000',
fontSize:20,
},
title:{
fontSize:20,
textAlign:'center',
},
})
答案 0 :(得分:0)
我遇到了同样的问题:https://github.com/farmisen/react-native-file-uploader/issues/11。基本上,确保它在MainApplication.java中正确链接(即在getPackages()方法中包含RCTFileUploaderPackage())。