RNFS.upload 当我想将设备中的文件发送到我的服务器时出现意外的流结束错误
RNFS.upload gives unexpected end of stream error while I want to send files in the device to my server
我正在使用 react-native-fs 发送我通过 react-native-document-picker 选择的文件。
所以我做了一个函数,当所有需要的文件都被选中时调用它,就像下面的代码一样。
当我调用函数 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)
文件是
[{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"}]
感谢您的帮助
您需要对所有嵌入项进行字符串化:
//Other code onTop
const {location, ...other} = payload;
form.append("location", JSON.stringify(location));
...
我强烈推荐你使用RNFetchBlob代替axios,别忘了将内容类型传递给您的 header.
很棒的编码
我正在使用 react-native-fs 发送我通过 react-native-document-picker 选择的文件。
所以我做了一个函数,当所有需要的文件都被选中时调用它,就像下面的代码一样。
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)
文件是
[{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"}]
感谢您的帮助
您需要对所有嵌入项进行字符串化:
//Other code onTop
const {location, ...other} = payload;
form.append("location", JSON.stringify(location));
...
我强烈推荐你使用RNFetchBlob代替axios,别忘了将内容类型传递给您的 header.
很棒的编码