![](/img/trans.png)
[英]Error: unexpected end of stream when upload file to server (react native fs)
[英]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 選擇的文件。 所以我制作了一個 function 並在選擇所有必需的文件時調用它,如下面的代碼。 當我調用 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)
文件是
[{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。
很棒的編碼
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.