简体   繁体   English

当我想将设备中的文件发送到我的服务器时,RNFS.upload 意外结束 stream 错误

[英]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.

相关问题 错误:将文件上传到服务器时流意外结束(反应本机 fs) - Error: unexpected end of stream when upload file to server (react native fs) Axios:流意外结束 - Axios: unexpected end of stream 在我的 m1 macbook 设备上初始化 react-native 应用程序时,它在下载包时出现 cocapods 错误 - While initializing react-native app on my m1 macbook device it gives cocapods error while downloading packages 使用 RNCamera 将本机图像上传到服务器会导致网络错误 - React native image upload to server using RNCamera gives network error 我收到此错误“npm ERR. JSON 输入意外结束,同时在尝试安装 expo-cli 时解析“...nPGP.js v3.0.4\r\nCom”附近 - I got this error “npm ERR! Unexpected end of JSON input while parsing near '…nPGP.js v3.0.4\r\nCom'” while trying to install expo-cli React Native:从 API 获取:意外的 JSON 文件结尾 - React Native: Fetching from API gives: Unexpected End Of JSON File npm错误-解析附近时JSON输入意外结束。 为什么? - npm error - Unexpected end of JSON input while parsing near. Why? 解析反应时 JSON 输入意外结束 - Unexpected end of JSON input while parsing react 每次我尝试运行我的反应应用程序时,它都会给我错误 - Evertime I try to run my react app it gives me error 将我的项目与Firebase连接以发送推送通知时出错 - Error while connecting my project with the firebase to send push notifications
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM