【问题标题】:how to upload photo in react native android如何在反应原生android中上传照片
【发布时间】:2016-08-31 07:56:58
【问题描述】:

我使用 react native 在 android 中进行开发。我想将文件或照片上传到服务器。我使用 react-native-file-uploader,但出现错误:

[未定义不是一个对象(评估 '_reactNative.NativeModules.FileUploader.upload')],Cannot read property 'upload' of undefined2

请帮忙,谢谢! 下面是我的代码:

 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',
},
}) 

【问题讨论】:

    标签: android reactjs upload native


    【解决方案1】:

    我遇到了同样的问题:https://github.com/farmisen/react-native-file-uploader/issues/11。基本上,确保它在 MainApplication.java 中正确链接(即在 getPackages() 方法中包含 RCTFileUploaderPackage())。

    【讨论】:

      猜你喜欢
      • 2018-01-31
      • 2021-02-25
      • 2020-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-25
      • 1970-01-01
      相关资源
      最近更新 更多