如何使用nodejs从azure blob存储读取csv文件?

wdebmtf2  于 2021-09-23  发布在  Java
关注(0)|答案(0)|浏览(335)

我已将csv文件上载到azure blob存储。现在我想从azure blob存储中检索该文件,我使用了以下代码。收到csv文件后,我将转换为json并进行一些操作。

var blob = require('../../service/blobstorage');
var chkFile = async function (req,res) { 
    let reqq = {
                           storageName:"consent",
                           blobFileName: "filename",
                           downloadFileName:"filenamee"
                }    
    let storeBlb = await blob.getBlobDataToStreamm(reqq,res)
}

在blobstorage文件中,

const getBlobDataToStreamm= async function(req, res){
try{
    var fs = require('fs');
    const storageName= req.storageName;
    const blobFileName= req.blobFileName;
    const downloadFileName= req.downloadFileName;
    res.setHeader("Content-Disposition", "attachment;filename=" + downloadFileName);
    res.setHeader("Content-Type", "text/csv");
    res.setHeader("Access-Control-Allow-Headers","X-Requested-With,content-type");
    blobService.getBlobToStream(storageName, blobFileName , res, function(error, result, response) {
        if(error){
            console.log('error',error);
            res.send({error:error, status: false});
        }
        else{
            console.log('resp',result);
            res.end();
        }
    })

  }catch(err){ 
    console.log("err ",err);
    res.send({error:err, status: false});
  }
}

chkfile();
但我得到了错误
err typeerror:无法读取未定义的属性“setheader”

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题