如何在解析器Js中更改内容标题?

时间:2019-04-30 13:35:07

标签: javascript mime-types content-type minio

我正在使用解析器js,

    var express = require('express');
var router = express.Router();
const parserController = require('../controllers/parsercontroller');
const multer = require('multer');
const upload = multer({ dest: 'uploads/' });
const odtupload = multer({ dest: 'odtuploads/' });
const uuid = require('uuid/v4');

/* post listing. */
router.post('/pdf', function (req, res, next) {
    // req.body = JSON.parse(req.body);
    console.log(req.body);
    var uuidfile = uuid();
    var outfile = process.env.filespath + uuidfile + '.odt';
    parserController.odtParser('odtuploads/'+req.body.fileID, outfile, req.body.data).then(data => {
        setTimeout(function () {
            var file = process.env.filespath + uuidfile + '.pdf';
            console.log(file);
            var metaData = {
                'Content-Type': 'application/octet-stream'

            }
            // Using fPutObject API upload your file to the bucket pdfreports.
            minioClient.fPutObject('pdfreports', uuidfile, file, metaData, function (err, etag) {
                if (err) return console.log(err);
                minioClient.presignedUrl('GET', 'pdfreports', uuidfile, 24 * 60 * 60, function (err, presignedUrl) {
                    if (err) {
                        res.status(500).send({ message: err });
                    } else {
                        res.status(200).send({ pdfUrl: presignedUrl });
                    }
                });
            });
        }, 3000);
    }).catch(error => {
        res.status(500).send({ message: error });
    });
});

router.post('/odt', odtupload.single("odt"), function (req, res, next) {
    var uuidfile = uuid();
    var metaData = {
        'Content-Type': 'application/octet-stream's

    }
    console.log(req.file);
    minioClient.fPutObject('odtfiles', req.file.originalname, req.file.path, metaData, function (err, etag) {
        if (err) {
            console.error(err);
            res.status(500).send({ message: err });
        };
        res.status(200).send({ id: req.file.filename });
    });
});


module.exports = router;

在这里,我从中获取URL,但是当我尝试使用此url在iframe中呈现pdf时,文件正在下载,但我需要使用此url呈现pdf,我尝试了Content-disposition:inline但它不管用。是否有任何更改内容标题的建议,以使文件不会被下载且可读? 给点光............

0 个答案:

没有答案