itinance / react-native-fs

Native filesystem access for react-native
MIT License
4.94k stars 976 forks source link

cannot be cast from Double to String for android #855

Open BhaumikSurani opened 4 years ago

BhaumikSurani commented 4 years ago

"react": "16.9.0", "react-native": "0.61.5", "react-native-fs": "2.16.4",

below code work properly in ios but not working on android it getting error casting error


var data = new Object();
data['intUserId'] = 5;
data['intActivityId'] = 8;
data['strStatus'] = 'OK';

RNFS.uploadFiles({
    toUrl: url,
    files: [{
        name: fileKey,
        filename: file.name,
        filetype: file.type,
        filepath: filePath,
    }],
    method: 'POST',
    headers: {
        //'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        //'Accept': 'application/json',
        'Accept': 'multipart/form-data',
        'Authorization': 'Basic ' + Base64.btoa(basicAuthUserName + ':' + basicAuthPassword),
    },
    fields: data,
    begin: ()=>{console.log("Uploading start")},
    progress: (response) => {
        var percentage = Math.floor((response.totalBytesSent/response.totalBytesExpectedToSend) * 100);
        console.log('UPLOAD IS ' + percentage + '% DONE!');
    }
})
.promise.then((response) => {
    console.log(JSON.stringify(response));
    if (response.statusCode == 200) {
        console.log("FILES UPLOADED!");
        console.log("Response :" + response.body);
    } else {
        console.log("SERVER ERROR");
    }
})
.catch((error) => {
    console.log("Exception :- " + error);
    //alert("Exception :- " + error);
});

Exception :- Error: Value for intUserId cannot be cast from Double to String

juanjsebgarcia commented 4 years ago

I'm seeing the same. If we look at the Typescript definition for Fields. type Fields = { [name: string]: string } It would appear it only accepts strings.

This can be worked around in the backend of course, but surely any JSON-able type should be permitted?

govind-v-natex commented 2 years ago

cannot be cast from Double to String for android, facing the same, please resolve this @itinance