itinance / itinance/react-native-fs

Unable to download PDF file with DownloadFile.

Open
#1,159 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

I am trying to download pdf content direclty from API but RNFS not providing how to pass fields with POST method with headers,

What I have tried
1) rn-fetch-blob
2) react-native-blob-utils

I want to
- Want to pass formdata with DownloadFile function with Authentication

Current Screnario
- DownloadFile Accept only headers parameters so I am able to pass Authentication but I also want to pass formdata along , This is the problem.

Code snippet

var dataForm = {
"username": username,
"id": invoiceno,
"request_source": 'app',
"request_app": 'user_app'
};
const d = new Date();
let ms = d.getSeconds().toString() + d.getMilliseconds().toString();
const fileName = 'Invoice'+ms+'.pdf';
const downloadHeaderPath = RNFS.DownloadDirectoryPath +"/" + fileName;
const headers = {
method: 'POST',
'Content-Type': 'multipart/form-data',
'Accept':'application/json',
body : dataForm,
'Authentication' : Authentication
};
console.log(headers);
// Download the file then read it, it should contain the headers we sent
RNFS.downloadFile({ fromUrl: 'XXXXXXXXXXXXXXXXXXXXXXXXXX', toFile: downloadHeaderPath, headers : headers}).promise.then(res => {
return RNFS.readFile(downloadHeaderPath, 'utf8');
}).then(content => {
const headers = JSON.parse(content);
console.log(headers);
// this.assert('Should contain header for foo', headers['HTTP_FOO'], 'Hello');
// this.assert('Should contain header for bar', headers['HTTP_BAR'], 'World');

// this.setState({ output: 'Headers downloaded successfully' });
}).catch(err => {
console.log(err);
});

Help me out.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.