Skip to content

Unable to download PDF file with DownloadFile. #1159

@dhameliyadharmesh

Description

@dhameliyadharmesh

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions