http header for downloading Microsoft Word and Excel files
Change this
header('Content-Type: application/msword');
to
header('Content-Type: application/octet-stream');
EDIT:
And change
header("Content-Disposition: attachment; filename='$No_$Name_$Test.docx");
to
header("Content-Disposition: attachment; filename=\"{$No}_{$Name}_{$Test}.docx\"");
Unable to open export excel file on hiding response headers using URL Rewrite
Okay so I was able to block all but Server response headers and I will share what worked for me so far:
X-AspNet-Version :
Just add the attribute enableVersionHeader="false"
to <httpRuntime/>
. It should look as follows :
<system.web>
<httpRuntime enableVersionHeader="false" />
</system.web>
X-Powered-By:
- Open IIS
- Select the Sitename under
Sites
folder - Select HTTP Response Headers under IIS
- Select
X-Powered-By
and remove the existing value and add an empty string.
Note: I will update once I am able to figure out a way to block server headers as well on this answer.
How to download excel (.xls) file from API in postman?
Try selecting send and download
instead of send
when you make the request. (the blue button)
https://www.getpostman.com/docs/responses
"For binary response types, you should select Send and download
which will let you save the response to your hard disk. You can then view it using the appropriate viewer."
How to download files using axios
When response comes with a downloadable file, response headers will be something like
Content-Disposition: "attachment;filename=report.xls"
Content-Type: "application/octet-stream" // or Content-type: "application/vnd.ms-excel"
What you can do is create a separate component, which will contain a hidden iframe.
import * as React from 'react';
var MyIframe = React.createClass({
render: function() {
return (
<div style={{display: 'none'}}>
<iframe src={this.props.iframeSrc} />
</div>
);
}
});
Now, you can pass the url of the downloadable file as prop to this component, So when this component will receive prop, it will re-render and file will be downloaded.
Edit: You can also use js-file-download module. Link to Github repo
const FileDownload = require('js-file-download');
Axios({
url: 'http://localhost/downloadFile',
method: 'GET',
responseType: 'blob', // Important
}).then((response) => {
FileDownload(response.data, 'report.csv');
});
Download MS Excel/Word via AngularJS call to a REST service
This is the Controller function I ended up using:
@RequestMapping(value = "/downloadDocx", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.CREATED)
public void downloadDocx(@RequestBody DocxInputBean docxInput,
HttpServletResponse response) throws Exception {
File docxFile = outputManager.createDocxProfile(docxInput);
response.setContentType("application/vnd.openxmlformats-officedocument.wordprocessingml.document");
InputStream is = new FileInputStream(docxFile);
org.apache.commons.io.IOUtils.copy(is, response.getOutputStream());
response.flushBuffer();
is.close();
}
Related Topics
How to Use Multiple PHP Header Content Types on the Same Page? Is This Possible
Soapclient: How to Pass Multiple Elements with Same Name
PHP - How to Translate a Website into Multiple Languages
How to Make MySQL Return Utf-8
PHP Making a Download Counter Without Leaving the Current Page
Fatal Error: Call to Undefined Function MySQL_Connect() in C:\Apache\Htdocs\Test.PHP on Line 2
Get a Single Row from the Database Using Ajax in Codeigniter
PHP Code Can Insert Image to Excel File and Open It Correctly in Ms Excel
How to Hide PHP File Extension Without Using .Htaccess
Merge Two Png Images with PHP Gd Library
Google Calendar API Batch Request PHP
Xpath in Simplexml for Default Namespaces Without Needing Prefixes
Firefox Error 'No Element Found'