RNFS.upload在我想将设备中的文件发送到服务器时给出了意外的流结束错误

问题描述 投票:1回答:1

我正在使用react-native-fs发送我由react-native-document-picker选择的文件。因此,当选择了所有必需的文件(如下面的代码)时,我将创建一个函数并调用它。enter image description here当我调用函数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"}]

谢谢您的帮助

react-native document react-native-fs
1个回答
0
投票

您需要对所有嵌入的项目进行分类:

//Other code onTop
const {location, ...other} = payload;
form.append("location", JSON.stringify(location));
...

和我强烈建议您使用RNFetchBlob代替Axios,不要忘记将内容类型传入标头。

大编码

© www.soinside.com 2019 - 2024. All rights reserved.