[英]RNFS.upload gives unexpected end of stream error while I want to send files in the device to my server
I am Using react-native-fs for sending the files I picked by react-native-document-picker.我正在使用 react-native-fs 发送我通过 react-native-document-picker 选择的文件。 so I make a function and call it when all the required files are selected like the code below.
所以我制作了一个 function 并在选择所有必需的文件时调用它,如下面的代码。
and when I call the function
uploadImageReq()
I got the following error on console当我调用 function
uploadImageReq()
我在控制台上收到以下错误
ERROR Error: unexpected end of stream
at Object.promiseMethodWrapper [as uploadFiles] (NativeModules.js:103)
at Object.uploadFiles (FS.common.js:594)
at uploadImageReq$ (AddScreen.js:73)
at tryCatch (runtime.js:45)
at Generator.invoke [as _invoke] (runtime.js:274)
at Generator.prototype.<computed> [as next] (runtime.js:97)
at tryCatch (runtime.js:45)
at invoke (runtime.js:135)
at runtime.js:170
at tryCallTwo (core.js:45)
the files is文件是
[{name: "imageFile", filename: "IMGs.jpg", filepath: "/data/user/0/com.bookland/cacheNONE/1201418716", filetype: "image/jpeg"},{name: "imageFile", filename: "IMGs.jpg", filepath: "/data/user/0/com.bookland/cacheNONE/1201418716", filetype: "image/jpeg"}]
Thank you for your helps谢谢你的帮助
You need to stringify all of your embeded items:您需要对所有嵌入项目进行字符串化:
//Other code onTop
const {location, ...other} = payload;
form.append("location", JSON.stringify(location));
...
and i strongly Recommend you to use RNFetchBlob instead of Axios, dont forget to pass content type in to your header.我强烈建议您使用RNFetchBlob而不是 Axios,不要忘记将内容类型传递给您的 header。
great coding很棒的编码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.