-
Notifications
You must be signed in to change notification settings - Fork 1k
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
- rn-fetch-blob
- 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.