Flutter downloader not downloading pdf file correctly

Viewed 211

I am using the below code for flutter downloader to download a pdf file

_setHeaders() => {
    'Authorization' : 'Bearer $token',
    'Content-Type' : "application/pdf",
    'Accept' : '*/*',
    'Content-disposition': "attachment",
};

final id = await FlutterDownloader.enqueue(
    url:"https://examplesite.com/api/v1/label_generate/24704",
    headers: _setHeaders(),
    savedDir: "/storage/emulated/0/Download",
    fileName: "label.pdf",
    showNotification: true,
    openFileFromNotification: true,
);

The file is getting downloaded, but when I open the pdf file I get the error Can not display pdf(label.pdf) is of invalid format.

How can I get a correct pdf file?

0 Answers
Related