0

I'm trying to upload in react-native but have no luck after many tries.

Someone please help me out of this problem? Thank you verymuch

const handleChoosePicture = () => {
    launchImageLibrary({ noData: true }, (response) => {
        if (response) {
            setChoosePicture(response);
        }
    });
}


const createFormData = (photo) => {
    const data = new FormData();
    data.append('files', {
        name: photo.fileName,
        type: photo.type,
        uri: Platform.OS === 'ios' ? photo.uri.replace('file://', '') : photo.uri,
    });
    return data;
};

const uploadImage = async (choosePicture) => {
    const Token = await AsyncStorage.getItem('member_token');
    await axios.post(
        `${AppConfig.apiUrl}/media/upload`,
        createFormData(choosePicture),
        {
            headers: {
                Accept: 'application/json',
                'Content-Type': 'multipart/form-data',
                authorization: `Bearer ${Token}`,
            },
        })
        .then((response) => {
            console.log('response', response);
        })
        .catch((error) => {
            console.log('error', error);
        });
}

enter image description here

enter image description here

enter image description here

enter image description here

Possible Unhandled Promise Rejection (id: 9):

TypeError: undefined is not an object (evaluating '_$$_REQUIRE(_dependencyMap[17], "axios").AxiosInstance.post')
imxitiz
  • 3,920
  • 3
  • 9
  • 33
Nam Apple
  • 3
  • 2

1 Answers1

0

I think you just need to restart the packager. If you are running a metro-packager and install a new dependency, you need to restart the packager so it can add the new dependencies to the dependencyMap.

[UPDATE]

You can also check if some of your libs is incompatible with your react-native version. I've just talked with a friend of mine, and he was with the same problem as you (dependencyMap) but with custom component, the problem in fact was react-native-gesture-handler that was in an old version

WitaloBenicio
  • 3,395
  • 5
  • 25
  • 32
  • Thanks for your comment, I have restart many times but no luck at all. – Nam Apple Apr 29 '21 at 13:28
  • Can you show how you are importing axios? Make sure you are importing: `import axios from 'axios'` – WitaloBenicio Apr 29 '21 at 14:04
  • @NamApple you can also check if some of your libs is incompatible with your react-native version. I've just talked with a friend of mine, and he was with the same problem as you (dependencyMap) but with custom component, the problem in fact was react-native-gesture-handler that was in an old version. – WitaloBenicio Apr 29 '21 at 23:07