0

I am getting error while creating blob type data using Node.js. I am explaining my code below.

saveFiles = async (res, outputJSON, testBedJson) => {
    const encodedOutput = btoa(JSON.stringify(outputJSON));
    let preName = 'intent_based';
    let fullFileName = `${preName}_${moment().format("hh_mm_ss-DD-MM-YYYY")}.ubot`;
    let fullFileTestBedJsonName = `test-bed_${moment().format("hh_mm_ss-DD-MM-YYYY")}.json`;
    const doc = new YAML.Document();
    doc.contents = testBedJson;
    let fullFileTestBedYmlName = `test-bed_${moment().format("hh_mm_ss-DD-MM-YYYY")}.yaml`;

    let ubotFileBlobContent = new Blob([encodedOutput], {type : 'text/plain'});
    let jsonFileBlobContent = new Blob([JSON.stringify(testBedJson, null, 4)], {type : 'application/json'});
    let yamlFileBlobContent = new Blob([doc.toString()], {type : 'text/yaml'});
    responseObj = {
        status: 'success',
        msg: 'Successfully saved the files',
        body: {
            allFiles:[
                {
                    "name": fullFileName,
                    "content": ubotFileBlobContent
                },
                {
                    "name": fullFileTestBedJsonName,
                    "content": jsonFileBlobContent
                },
                {
                    "name": fullFileTestBedYmlName,
                    "content": yamlFileBlobContent
                }
            ]
        }
    }
    res.send(responseObj);
 }

So here I am trying to convert to blob type data and returning to UI for download. But as per my code I am receiving the following error.

Error:: ReferenceError: Blob is not defined
    at saveFiles (/Users/subhrajp/ubot-git/uBot/python3.7-alpine3.8/app/mean-stack/node-js/controller/usecaseWorkflowCtrl.js:2019:31)
    at Object.downloadUbotIntentBased (/Users/subhrajp/ubot-git/uBot/python3.7-alpine3.8/app/mean-stack/node-js/controller/usecaseWorkflowCtrl.js:1326:23)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at async /Users/subhrajp/ubot-git/uBot/python3.7-alpine3.8/app/mean-stack/node-js/app.js:262:27

Here I need to convert to blob type data instead of writing into file. Please can anybody suggest how to resolve this issue using Node.js.

subhra_user
  • 439
  • 5
  • 19

0 Answers0