Angular2 + Express.js:返回CSV并提供可下载文件?

时间:2017-01-30 20:46:44

标签: node.js angular express

我的ng2组件中有这段代码:

Response with status: 200 OK for URL: https://MYURL/URI/data.csv

然后保存了一个文件,但文件内容为:

'use strict'; const Transactions = require('../../models').transaction; module.exports = function * details(req, res) { logger.debug(' Get TME details ' + req.currentTME._id); const transaction = yield Transactions.findOne({ _tme: req.currentTME.id }).lean(); return res .json({ status: constants.status.SUCCESS, timemodel: req.currentTME, linkedInfo: { transaction } }); };

我的后端是node / express,我是否必须为此创建一个流,或者它是否可以像以前一样使用直接文件访问?

这是我的后端,如何更改它以返回流?

 request(url: string, data: any, method: RequestMethod, showErrorDialog = true): Observable<any> {

    const requestOptionsArgs: RequestOptionsArgs = {

        url: this.baseUrl + url,
        method: method,
        headers: this.createHeaders(),
        body: JSON.stringify(data)
    };

    this.log.info(this.getCurl(requestOptionsArgs), this);

    const requestOptions: RequestOptions = new RequestOptions(requestOptionsArgs);

    return this.intercept(
        this.http.request(new Request(requestOptions)).timeout(3000),
        requestOptionsArgs,
        showErrorDialog
    ).share();
}

完整服务器调用:

javax.servlet.annotation.MultipartConfig,javax.servlet.annotation.WebServlet

0 个答案:

没有答案