Hussian Shaik February 2016

how to save an uploaded image in react-native

native-image-picker code to upload the image,What the problem when uploading the image it uploads and show the selected image, but when i want to save the image in database, It saves like [object Object] in data base. When i want to to Get the data the image is not showing.

  • Here i am attaching my my code:

    var {
        StyleSheet,
        View,
        Image,
        Text,
        TouchableOpacity,
        AlertIOS,
        TextInput,
        ScrollView,
        NativeModules: {
            UIImagePickerManager
        }
    } = React;
    
    class Profile extends React.Component {
        constructor(props) {
            super(props);
            this.state = {
                avatarSource: this.props.data.data.profilepic,
            };
        }
        avatarTapped() {
            var options = {
                title: 'Select Photo',
                cancelButtonTitle: 'Cancel',
                takePhotoButtonTitle: 'Take Photo',
                chooseFromLibraryButtonTitle: 'Choose From Library',
                allowsEditing: true,
                returnBase64Image: false,
                returnIsVertical: false,
                quality: 0.8,
                noData: true,
                storageOptions: {
                    skipBackup: true
                }
            }
    
            UIImagePickerManager.showImagePicker(options, (didCancel, response) => {
                console.log('Response = ', response);
    
                if (didCancel) {
                    console.log('User cancelled image picker');
                } else {
                    if (response.customButton) {
                        console.log('User tapped custom button: ', response.customButton);
                    } else {
                        // You can display the image using either:
                        //var source = {uri: 'data:image/jpeg;base64,' + response.data, isStatic: true};
                        // var source = response.uri ;
                        var source = {
                            uri: response.uri.replace('file://', ''),
                            isStatic: true
                        };
                                

Answers


AKADER February 2016

Edit: I mean object object I want to post a Comment but I am short a couple of points. [object object] means it is a object object. There are different types of objects in javascript. try JSON.parse(source)

Post Status

Asked in February 2016
Viewed 3,738 times
Voted 6
Answered 1 times

Search




Leave an answer