Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

React native fs unable to upload file to API

$
0
0

When i try to upload the file from "react-native-fs" uploadFiles. File not uploading. But file is present in RNFS.DocumentDirectoryPath

enter image description here

var files = [{name: "CCM_Errorlog",filename: "CCM_Errorlog_" + now + "_" + driverIdNew + ".txt",filepath: RNFS.DocumentDirectoryPath + "/CCM_Errorlog_Copy.txt"}];

RNFS.uploadFiles({
        toUrl: uploadUrl,
        binaryStreamOnly:true,
        files: files,
        method: "POST",
        headers: {
          Accept: "application/json",
        },
        begin: uploadBegin,
        progress: uploadProgress
      })
        .promise.then(response => {
          console.log("Response_up:"+ JSON.stringify(response));
          if (response.statusCode == 200) {
            console.log("FILES UPLOADED!:" + JSON.stringify(response)); // response.statusCode, response.headers, response.body
            alert(JSON.stringify(response));
          } else {
            alert(JSON.stringify(response));
            console.log(response);
            console.log(RNFS.DocumentDirectoryPath);
          }
        })
        .catch(err => {
          if (err.description === "cancelled") {
            // cancelled by user
            console.log("Uploading Canceleed by User");
          }
          alert("uploadFile Error" + err);
        });

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>