React-native-fetch-blob: Android upload issues

Created on 25 Aug 2016  ·  3Comments  ·  Source: wkh237/react-native-fetch-blob

"react-native": "0.31.0",
"react-native-fetch-blob": "^0.9.3",

`let files = images.map((item, index)=> {
return {name: index, filename: index + '.png', data: rnfb.wrap(item.uri)}
});
let option = {
'Content-Type': 'multipart/form-data'
};

rnfb.fetch('POST', 'http://xxxxx/upload', option, files)
.catch(e=>Alert.alert('警告', '数据处理异常。'))`

IOS is no problem, but the Android

RNFetchBlob failed to create request multipart body:TypeError:expected dynamic type string,but had type int64

android bug needs feedback

Most helpful comment

@cheng0112 , I've found here the problem is. The name property should be a string rather than a number. I think simply change type of index will fix it 👍

let files = images.map((item, index)=> {
-    return {name: index, filename: index + '.png', data: rnfb.wrap(item.uri)}                                              
+    return {name: String(index), filename: index + '.png', data: rnfb.wrap(item.uri)}                                              });
let option = {
    'Content-Type': 'multipart/form-data'
};

rnfb.fetch('POST', 'http://xxxxx/upload', option, files)
.catch(e=>Alert.alert('警告', '数据处理异常。'))`

All 3 comments

@cheng0112 , Thank you for reporting this issue, I'll look into it 😄

@cheng0112 , I've found here the problem is. The name property should be a string rather than a number. I think simply change type of index will fix it 👍

let files = images.map((item, index)=> {
-    return {name: index, filename: index + '.png', data: rnfb.wrap(item.uri)}                                              
+    return {name: String(index), filename: index + '.png', data: rnfb.wrap(item.uri)}                                              });
let option = {
    'Content-Type': 'multipart/form-data'
};

rnfb.fetch('POST', 'http://xxxxx/upload', option, files)
.catch(e=>Alert.alert('警告', '数据处理异常。'))`

@cheng0112 , I've found here the problem is. The name property should be a string rather than a number. I think simply change type of index will fix it 👍

let files = images.map((item, index)=> {
-    return {name: index, filename: index + '.png', data: rnfb.wrap(item.uri)}                                              
+    return {name: String(index), filename: index + '.png', data: rnfb.wrap(item.uri)}                                              });
let option = {
    'Content-Type': 'multipart/form-data'
};

rnfb.fetch('POST', 'http://xxxxx/upload', option, files)
.catch(e=>Alert.alert('警告', '数据处理异常。'))`

Thank you so much!!! I was all over on the internet due to this. Params are not accepting if it's not a string.

Was this page helpful?
0 / 5 - 0 ratings