簡體   English   中英

當我想將設備中的文件發送到我的服務器時,RNFS.upload 意外結束 stream 錯誤

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM