开发者社区> 问答> 正文

函数计算,http触发,总是返回头 Content-Disposition:attachment

函数计算http服务
返回的结果总是包含头:Content-Disposition:attachment
导致页面不能在浏览器上显示,而是变成下载

代码如下:(nodejs)
var getRawBody = require('raw-body');
var getFormBody = require('body/form');
var body = require('body');


/*
if you open the initializer feature, please implement the initializer function, as below:
module.exports.initializer = function(context, callback) {
    console.log('initializing');
    callback(null, '');
};
*/

module.exports.handler = function(req, resp, context) {
    console.log('hello world');

    var params = {
        path: req.path,
        queries: req.queries,
        headers: req.headers,
        method : req.method,
        requestURI : req.url,
        clientIP : req.clientIP,
    }
        
    getRawBody(req, function(err, body) {
        resp.deleteHeader('Content-Disposition');
        for (var key in req.queries) {
          var value = req.queries[key];
          resp.setHeader(key, value);
        }
        resp.deleteHeader('Content-Disposition');
        resp.setHeader('Content-Disposition', 'inline');
        params.body = body;
        resp.send(JSON.stringify(params, null, 4));
    }); 
      
    /*
    getFormBody(req, function(err, formBody) {
        for (var key in req.queries) {
          var value = req.queries[key];
          resp.setHeader(key, value);
        }
        params.body = formBody;
        console.log(formBody);
        resp.send(JSON.stringify(params));
    }); 
    */
}


展开
收起
1524707224747817 2019-05-21 23:32:17 3186 0
1 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
Hologres Serverless之路:揭秘弹性计算组 立即下载
Serverless开发平台: 让研发效能再提升 立即下载
Serverless 引领云上研发新范式 立即下载