I see "deprecated" here even though it's working.
If this feature to be deprecated soon, what's the alternative way to apply an uploaded excel template?
I see "deprecated" here even though it's working.
If this feature to be deprecated soon, what's the alternative way to apply an uploaded excel template?
Yes, you're right, yesterday I tried it without the azure-sb and it worked, but I don't know why it is crushing on the connection sb string (required by bus).
Currently I don't need more than one instance, but I'll have to look into it later.
The error log:
2020-10-28T12:29:08.692Z INFO - Pulling image from Docker hub: jsreport/jsreport:2.10.0-full
2020-10-28T12:29:09.740Z INFO - 2.10.0-full Pulling from jsreport/jsreport
2020-10-28T12:29:09.742Z INFO - Digest: sha256:62d10967695ede1be8d74a0f274d50ec4365e3e54dc470ee5d5cc7dcb52d3967
2020-10-28T12:29:09.744Z INFO - Status: Image is up to date for jsreport/jsreport:2.10.0-full
2020-10-28T12:29:09.747Z INFO - Pull Image successful, Time taken: 0 Minutes and 1 Seconds
2020-10-28T12:29:09.754Z INFO - Starting container for site
2020-10-28T12:29:09.755Z INFO - docker run -d -p 5614:5488 --name jsreportwebapp_0_c1eb759d -e WEBSITES_ENABLE_APP_SERVICE_STORAGE=false -e WEBSITE_SITE_NAME=JsReportWebApp -e WEBSITE_AUTH_ENABLED=False -e PORT=5488 -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=jsreportwebapp.azurewebsites.net -e WEBSITE_INSTANCE_ID=0ba78dffa618a60516959c0666483417863a6a3954d0cd16e20f72ea2335e9cb jsreport/jsreport:2.10.0-full npm start
2020-10-28T12:29:09.756Z INFO - Logging is not enabled for this container.Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2020-10-28T12:29:10.903Z INFO - Initiating warmup request to container jsreportwebapp_0_c1eb759d for site jsreportwebapp
2020-10-28T12:29:11.179153847Z
2020-10-28T12:29:11.179219348Z > jsreport-server@ start /app
2020-10-28T12:29:11.179239448Z> node server
2020-10-28T12:29:11.179243348Z
2020-10-28T12:29:11.598631112Z 2020-10-28T12:29:11.597Z - [32minfo[39m: Initializing jsreport@2.10.0 in production mode using configuration file: jsreport.config.json
2020-10-28T12:29:11.600602223Z 2020-10-28T12:29:11.600Z - [32minfo[39m: Searching for available extensions in /app/
2020-10-28T12:29:11.605321147Z 2020-10-28T12:29:11.605Z - [32minfo[39m: Extensions location cache not found, crawling directories
2020-10-28T12:29:12.560071275Z 2020-10-28T12:29:12.559Z - [32minfo[39m: Found 52 extensions
2020-10-28T12:29:12.788647454Z 2020-10-28T12:29:12.788Z - [32minfo[39m: Setting dedicated-process (process based) strategy for rendering. Please visit http://jsreport.net/learn/configuration for information how to get more performance.
2020-10-28T12:29:12.795650290Z 2020-10-28T12:29:12.795Z - [32minfo[39m: Using extension authentication@2.6.0
2020-10-28T12:29:12.822164327Z 2020-10-28T12:29:12.822Z - [32minfo[39m: Using extension azure-storage@1.1.1
2020-10-28T12:29:13.036189232Z 2020-10-28T12:29:13.034Z - [32minfo[39m: Using extension cli@2.2.5
2020-10-28T12:29:13.038022641Z 2020-10-28T12:29:13.036Z - [32minfo[39m: Using extension debug@2.1.3
2020-10-28T12:29:13.039801051Z 2020-10-28T12:29:13.038Z - [32minfo[39m: Using extension ejs@2.2.0
2020-10-28T12:29:13.039859051Z 2020-10-28T12:29:13.038Z - [32minfo[39m: Using extension express@2.8.0
2020-10-28T12:29:13.129383813Z 2020-10-28T12:29:13.129Z - [32minfo[39m: Using extension fop-pdf@2.2.0
2020-10-28T12:29:13.160836575Z 2020-10-28T12:29:13.160Z - [32minfo[39m: Using extension freeze@2.0.0
2020-10-28T12:29:13.162321883Z 2020-10-28T12:29:13.162Z - [32minfo[39m: Using extension handlebars@2.1.0
2020-10-28T12:29:13.165156098Z 2020-10-28T12:29:13.164Z - [32minfo[39m: Using extension import-export@2.1.0
2020-10-28T12:29:13.205815907Z 2020-10-28T12:29:13.205Z - [32minfo[39m: Using extension jsrender@2.1.1
2020-10-28T12:29:13.206516011Z 2020-10-28T12:29:13.206Z - [32minfo[39m: Using extension mongodb-store@1.3.3
2020-10-28T12:29:13.322941312Z 2020-10-28T12:29:13.322Z - [32minfo[39m: Using extension mssql-store@1.4.0
2020-10-28T12:29:13.576306720Z 2020-10-28T12:29:13.576Z - [32minfo[39m: Using extension postgres-store@1.3.1
2020-10-28T12:29:13.723635880Z 2020-10-28T12:29:13.723Z - [32minfo[39m: Using extension pug@3.1.0
2020-10-28T12:29:13.724238383Z 2020-10-28T12:29:13.724Z - [32minfo[39m: Using extension tags@2.5.0
2020-10-28T12:29:13.729411010Z 2020-10-28T12:29:13.726Z - [32minfo[39m: Using extension templates@2.4.0
2020-10-28T12:29:13.729430410Z 2020-10-28T12:29:13.728Z - [32minfo[39m: Using extension authorization@2.4.0
2020-10-28T12:29:13.731568621Z 2020-10-28T12:29:13.731Z - [32minfo[39m: Using extension base@2.0.2
2020-10-28T12:29:13.732925728Z 2020-10-28T12:29:13.732Z - [32minfo[39m: Using extension browser-client@2.2.2
2020-10-28T12:29:13.734773337Z 2020-10-28T12:29:13.734Z - [32minfo[39m: Using extension child-templates@1.4.0
2020-10-28T12:29:13.737931054Z 2020-10-28T12:29:13.737Z - [32minfo[39m: Using extension chrome-pdf@1.9.0
2020-10-28T12:29:13.789858922Z 2020-10-28T12:29:13.789Z - [32minfo[39m: Using extension data@2.4.0
2020-10-28T12:29:13.790592325Z 2020-10-28T12:29:13.790Z - [32minfo[39m: Using extension docx@2.8.0
2020-10-28T12:29:13.793969743Z 2020-10-28T12:29:13.793Z - [32minfo[39m: Using extension electron-pdf@3.2.0
2020-10-28T12:29:13.843202297Z 2020-10-28T12:29:13.842Z - [32minfo[39m: Using extension fs-store@2.9.0
2020-10-28T12:29:13.933931165Z 2020-10-28T12:29:13.933Z - [32minfo[39m: Using extension html-embedded-in-docx@2.2.0
2020-10-28T12:29:13.935713974Z 2020-10-28T12:29:13.935Z - [32minfo[39m: Using extension html-to-text@2.1.0
2020-10-28T12:29:13.938389188Z 2020-10-28T12:29:13.938Z - [32minfo[39m: Using extension licensing@2.2.3
2020-10-28T12:29:13.940992602Z 2020-10-28T12:29:13.940Z - [32minfo[39m: Using extension pdf-utils@1.9.0
2020-10-28T12:29:13.997348193Z 2020-10-28T12:29:13.997Z - [32minfo[39m: Using extension phantom-image@2.1.0
2020-10-28T12:29:14.016827893Z 2020-10-28T12:29:14.016Z - [32minfo[39m: Using extension phantom-pdf@2.6.0
2020-10-28T12:29:14.020812714Z 2020-10-28T12:29:14.020Z - [32minfo[39m: fs store underlying changes synchronization with studio is disabled
2020-10-28T12:29:14.022409822Z 2020-10-28T12:29:14.022Z - [32minfo[39m: Using extension pptx@0.7.0
2020-10-28T12:29:14.029934561Z 2020-10-28T12:29:14.029Z - [32minfo[39m: Using extension reports@2.5.0
2020-10-28T12:29:14.032798676Z 2020-10-28T12:29:14.032Z - [32minfo[39m: Using extension static-pdf@0.4.0
2020-10-28T12:29:14.035767191Z 2020-10-28T12:29:14.035Z - [32minfo[39m: Using extension studio@2.10.1
2020-10-28T12:29:14.086832154Z 2020-10-28T12:29:14.086Z - [32minfo[39m: Using extension text@2.0.0
2020-10-28T12:29:14.087435458Z 2020-10-28T12:29:14.087Z - [32minfo[39m: Using extension version-control@1.5.1
2020-10-28T12:29:14.135980108Z 2020-10-28T12:29:14.135Z - [32minfo[39m: Using extension wkhtmltopdf@2.3.0
2020-10-28T12:29:14.170166885Z 2020-10-28T12:29:14.169Z - [32minfo[39m: Using extension assets@1.7.0
2020-10-28T12:29:14.189873186Z 2020-10-28T12:29:14.189Z - [32minfo[39m: Using extension fs-store-aws-s3-persistence@1.4.0
2020-10-28T12:29:14.248266088Z 2020-10-28T12:29:14.248Z - [32minfo[39m: Using extension fs-store-aws-sns-sync@1.2.1
2020-10-28T12:29:14.314685530Z 2020-10-28T12:29:14.314Z - [32minfo[39m: Using extension fs-store-azure-sb-sync@1.1.0
2020-10-28T12:29:14.391988629Z 2020-10-28T12:29:14.391Z - [32minfo[39m: Using extension fs-store-azure-storage-persistence@1.2.0
2020-10-28T12:29:14.457352067Z 2020-10-28T12:29:14.457Z - [32minfo[39m: Using extension html-to-xlsx@2.8.0
2020-10-28T12:29:14.646457043Z 2020-10-28T12:29:14.646Z - [32minfo[39m: html-to-xlsx detected chrome as available html engine
2020-10-28T12:29:14.646506043Z 2020-10-28T12:29:14.646Z - [32minfo[39m: html-to-xlsx detected phantom as available html engine
2020-10-28T12:29:14.647549948Z 2020-10-28T12:29:14.646Z - [32minfo[39m: Using extension scheduling@2.5.0
2020-10-28T12:29:14.679678714Z 2020-10-28T12:29:14.679Z - [32minfo[39m: Using extension scripts@2.6.0
2020-10-28T12:29:14.682388028Z 2020-10-28T12:29:14.682Z - [32minfo[39m: Using extension studio-theme-dark@0.3.0
2020-10-28T12:29:14.682957531Z 2020-10-28T12:29:14.682Z - [32minfo[39m: Using extension xlsx@2.5.0
2020-10-28T12:29:14.780423434Z 2020-10-28T12:29:14.780Z - [32minfo[39m: Using extension public-templates@2.2.0
2020-10-28T12:29:14.781107738Z 2020-10-28T12:29:14.780Z - [32minfo[39m: Using extension resources@2.1.0
2020-10-28T12:29:14.781803741Z 2020-10-28T12:29:14.781Z - [32minfo[39m: Using extension sample-template@2.6.0
2020-10-28T12:29:14.783461750Z 2020-10-28T12:29:14.783Z - [32minfo[39m: Using general timeout for rendering (reportTimeout: 60000)
2020-10-28T12:29:14.783497050Z 2020-10-28T12:29:14.783Z - [32minfo[39m: Using fs provider for template store.
2020-10-28T12:29:14.790343385Z 2020-10-28T12:29:14.790Z - [32minfo[39m: fs store is persisting using azure-storage
2020-10-28T12:29:14.810150288Z 2020-10-28T12:29:14.809Z - [32minfo[39m: fs store is synchronizing using azure-sb
2020-10-28T12:29:14.811900497Z 2020-10-28T12:29:14.811Z - [31merror[39m: Error occured during reporter init Error: Invalid connection string setting key "defaultendpointsprotocol"
2020-10-28T12:29:14.811942797Z at /app/node_modules/azure-common/lib/services/servicesettings.js:78:13
2020-10-28T12:29:14.811950297Z at Array.forEach (<anonymous>)
2020-10-28T12:29:14.811954597Z at Object.exports.parseAndValidateKeys (/app/node_modules/azure-common/lib/services/servicesettings.js:76:34)
2020-10-28T12:29:14.811958897Z at Function.ServiceBusSettings.createFromConnectionString (/app/node_modules/azure-common/lib/services/servicebussettings.js:164:43)
2020-10-28T12:29:14.811962997Z at ServiceBusServiceBase (/app/node_modules/azure-sb/lib/servicebusservicebase.js:57:45)
2020-10-28T12:29:14.811966997Z at new ServiceBusService (/app/node_modules/azure-sb/lib/servicebusservice.js:69:31)
2020-10-28T12:29:14.811970797Z at Object.exports.createServiceBusService (/app/node_modules/azure-sb/lib/servicebus.js:39:10)
2020-10-28T12:29:14.811974697Z at module.exports (/app/node_modules/jsreport-fs-store-azure-sb-sync/lib/syncAzureServiceBus.js:20:27)
2020-10-28T12:29:14.811978597Z at /app/node_modules/jsreport-fs-store-azure-sb-sync/lib/main.js:9:54
2020-10-28T12:29:14.811992397Z at Object.load (/app/node_modules/jsreport-fs-store/lib/provider.js:78:21)
2020-10-28T12:29:14.811996597Z at Object.init (/app/node_modules/jsreport-core/lib/store/documentStore.js:188:29)
2020-10-28T12:29:14.812000497Z at Reporter.init (/app/node_modules/jsreport-core/lib/reporter.js:244:32)
2020-10-28T12:29:14.812442499Z Error: Invalid connection string setting key "defaultendpointsprotocol"
2020-10-28T12:29:14.812456199Z at /app/node_modules/azure-common/lib/services/servicesettings.js:78:13
2020-10-28T12:29:14.812460999Z at Array.forEach (<anonymous>)
2020-10-28T12:29:14.812465100Z at Object.exports.parseAndValidateKeys (/app/node_modules/azure-common/lib/services/servicesettings.js:76:34)
2020-10-28T12:29:14.812469300Z at Function.ServiceBusSettings.createFromConnectionString (/app/node_modules/azure-common/lib/services/servicebussettings.js:164:43)
2020-10-28T12:29:14.812473300Z at ServiceBusServiceBase (/app/node_modules/azure-sb/lib/servicebusservicebase.js:57:45)
2020-10-28T12:29:14.812477300Z at new ServiceBusService (/app/node_modules/azure-sb/lib/servicebusservice.js:69:31)
2020-10-28T12:29:14.812481200Z at Object.exports.createServiceBusService (/app/node_modules/azure-sb/lib/servicebus.js:39:10)
2020-10-28T12:29:14.812493700Z at module.exports (/app/node_modules/jsreport-fs-store-azure-sb-sync/lib/syncAzureServiceBus.js:20:27)
2020-10-28T12:29:14.812497600Z at /app/node_modules/jsreport-fs-store-azure-sb-sync/lib/main.js:9:54
2020-10-28T12:29:14.812501400Z at Object.load (/app/node_modules/jsreport-fs-store/lib/provider.js:78:21)
2020-10-28T12:29:14.812505200Z at Object.init (/app/node_modules/jsreport-core/lib/store/documentStore.js:188:29)
2020-10-28T12:29:14.812509000Z at Reporter.init (/app/node_modules/jsreport-core/lib/reporter.js:244:32)
2020-10-28T12:29:14.829984890Z npm ERR! code ELIFECYCLE
2020-10-28T12:29:14.830633393Z npm ERR! errno 1
2020-10-28T12:29:14.831717699Z npm ERR! jsreport-server@ start: `node server`
2020-10-28T12:29:14.832027600Z npm ERR! Exit status 1
2020-10-28T12:29:14.832038601Z npm ERR!
2020-10-28T12:29:14.832092901Z npm ERR! Failed at the jsreport-server@ start script.
2020-10-28T12:29:14.832101001Z npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2020-10-28T12:29:14.840897146Z
2020-10-28T12:29:14.840927146Z npm ERR! A complete log of this run can be found in:
2020-10-28T12:29:14.840933846Z npm ERR! /home/jsreport/.npm/_logs/2020-10-28T12_29_14_832Z-debug.log
Most relevant line:
2020-10-28T12:29:14.811900497Z 2020-10-28T12:29:14.811Z - [31merror[39m: Error occured during reporter init Error: Invalid connection string setting key "defaultendpointsprotocol"
2020-10-28T12:29:14.811942797Z at /app/node_modules/azure-common/lib/services/servicesettings.js:78:13
Note that I rechecked the inputted value and it's surely not just "defaultendpointsprotocol", it seems there's a bug in that jsreport container?
Note that when I put the store configuration in a local jsreport app, it worked, the templates were uploaded to that azure storage, but however it's not working on the web app where I am using the container you're providing.
In the local storage I noticed there's no 'connection string' required but just accountName and accountKey for fs-store-azure-storage-persistence
I followed the same instrunctions mentioned on your site.https://jsreport.net/blog/render-reports-using-azure-app-service
The azure storage Connection string looks like this:
DefaultEndpointsProtocol=https;AccountName=storageaccountxxxxx;AccountKey=xxxxxxxx/xxxxx/xxxxxxxx==;EndpointSuffix=core.windows.net
The jsReport's azure web app is throwing "invalid connection string error". I rechecked the value and it's as provided from azure storage
Any idea?
I am stupid, i mixed up between 2.1.0 and 2.10
i am happy with Azure web app and it's way faster than the Azure functions jserport (which is not working as expected).
Azure web app is working as expected and successful generated reports via post.
I followed these step by step, even using the same docker image, since so far I am failing to make it work as azure functions (check the previous thread):
https://jsreport.net/blog/render-reports-using-azure-app-service
This how the jsreport looks in your documentation, and it looks the same as my local jsreport app (I used the ready kit for azure functions).
This how my deployed azure web app looks like:
It looks totally different??
This one doesn't support metadata and not fully compatible with the other.
My local app :
version: 2.10.0
engines:
handlebars, jsrender, none
recipes:
chrome-image, chrome-pdf, docx, html, html-to-xlsx, html-with-browser-client, pptx, static-pdf, text, xlsx
The one in docker......I dunno, I see no "About" there. And it also throwing "Chromium revision is not downloaded. Run "npm install" or "yarn install"" when attempting to create a report.
What about these incompatibilities? Is there other docker images? I am totally lost there.
Hi,
Sorry, I know I am asking a lot of questions, but I am working on big reports and it's all new to me: jsReport, Azure Functions, handlebars....I am unfamiliar with all these.
So this my studio, invoice is just a test template:
ALL reports are working fine in the studio.
and this is the main function that i am calling jsReport:
/**
* @function fetchReport It's the Promise function that sends a post request to jsReport server (using axios)
* then it pipes the response to a streamObj, the promise is resolved after finishing writing the stream to the temp folder
* @param {string} path the path to temp folder
* @param {object} data The object needed to generate report in jsReport server (a Functions App)
* @param {string} functionName The name of the Azure's function in jsReport app, for now there's only one.
* @param {string} reportName it's the name of the report template configured in jsReport.
*/
const fetchReport = (path, data, functionName, reportName) => {
return new Promise(async (resolve, reject) => {
let jsr = process.env.JSREPORTURL + "/api/" + functionName;
let options = {
url: jsr, //valid string to report api
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
responseType: "stream",
maxContentLength: Infinity,
maxBodyLength: Infinity,
};
let response = await axios.post(
jsr,
{
template: { name: reportName },
data: data,
},
options
);
if(response.data){
let writeStream = response.data
.pipe(fs.createWriteStream(path))
.on("finish", () => {
resolve(writeStream);
});
}
else {
reject(null);
}
}).catch((e) => {
console.log("ERROR");
console.log(e);
});
};
functionName is always "report"
and reportName is the name of my target template.
and process.env.JSREPORTURL is either localhost:5488 or the azure function url :https://xxxxxxxxx.azurewebsites.net
When I am testing this from local to local, it's all working fine, if I pass "executive" as reportName, I get the executive report filled with data, if I pass "single", I get the right report....and so on.
BUT when I try from my local to my deployed azure function, only the "invoice" report is working when I pass anything else the axios is returning 400
This is my azure deployed function:
I noticed the the default template after the || operator, so maybe that's why only the 'invoice' is returning a report?
Am I missing something, should I deploy a separate function for each template/report ? Please help.
Should I apply it somewhere in environment?
Or does it take it from VS Code deploying?
So I need to make a merge between two reports like this:
So this what I did; I 've created an empty template, and put this in config:
It works well, except that it's printing the first "mother" page:
I don't want to create a new template containing two reports, that would mean double maintenance, I just need to delete this white page.
Is there a way to hide it? This is ALL what i need to solve this: Delete first page (or last page if I do prepend instead).
@bjrmatos any solution? I am repeating myself for a lot of functions, does the module.export should work for these registered helpers?
This thread is so old and no longer relevant and solution needs to be updated.
I've tried the following; but it's throwing error:
And there's no "assets" folder, there's assets in each folder.
it is ok, i figured out long ago.
I must admit, this is the best js reporting engine I've ever encountered, very good job guys.
I have tried it and it didn't work for header, only the main template is accessing data.
@bjrmatos Ok another question: I picked the Azure Functions to deploy jsreport....andd I am still not quite sure if it was the best choice for us, I must be sure that I can use all jsreport's functionalities.
Does the scheduling extension can work on Azure Functions?? I mean It requires CRON operations and Azure Functions in not a real running app but just a bunch of api functions. Please confirm back whether scheduling is possible on Azure functions and if yes, how it can be possible?
Hi jsreport team,
I am still learning the framework and reading the tutorials https://jsreport.net/learn/periodical-report-sending-through-email
Is there a way to create email/schedules in a CRUD function programmatically via http request?
Like I want the users to be able to crate schedules destined for their emails.
I solved it by wraping the fetchReport function with new Promise, after doing some logging I realized that the fetchReprot (which has the write stream) is finishing before sending the file to client:
var fetchReport = (path, data, functionName) => {
return new Promise(async resolve => {
let jsr = process.env.JSREPORTURL + "/api/" + functionName;
let options = {
// auth: { user: 'admin', password: 'samer'},
url: jsr, //valid string to report api
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
responseType: "stream",
maxContentLength: Infinity,
maxBodyLength: Infinity,
};
let response = await axios.post(
jsr,
{
template: { name: "invoice" },
data: data,
},
options
);
let writeStream = response.data.pipe(fs.createWriteStream(path))
.on('finish', () => {
console.log("ONE");
resolve(writeStream);
})
})
};
But I am not sure why it works, I thought that a Async function should behave like a function returning a new Promise?
When I was testing the below on local (and calling a local jsreport), everything was working fine.
const axios = require("axios");
const express = require("express");
const router = express.Router();
const fs = require("fs");
const apiHelp = require("../../utf/common/apiReturnHelper");
router.use(function (req, res, next) {
next();
});
router.post("/report", async function (req, res) {
if (!req.session.currentUser){
return res.json(apiHelp.noSession());
}
if (!req.body.data || !req.body.functionName){
return res.json(apiHelp.error({message:"missingData"}));
}
let data = req.body.data;
let functionName = req.body.functionName;
let unixTimeStamp = new Date().getTime() / 1000; //unix timestamp
let fileName = unixTimeStamp + "_report.pdf";
let path = "temp/" + fileName;
await fetchReport(path, data, functionName);
fs.createReadStream(path).pipe(res).on('end', res.end);
fs.access(path, fs.constants.R_OK, (err) => {
console.log("\n> Checking Permission for reading the file");
if (err) console.error("No Read access");
else {
setTimeout(()=> {
fs.unlink(path, function (err) {
if (err) {
console.log("No file found");
}
console.log("File deleted!");})
},3000);}
});
});
var fetchReport = async (path, data, functionName) => {
try {
let jsr = process.env.JSREPORTURL + "/api/" + functionName;
let options = {
// auth: { user: 'admin', password: 'samer'},
url: jsr, //valid string to report api
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
responseType: "stream",
maxContentLength: Infinity,
maxBodyLength: Infinity,
};
let response = await axios.post(
jsr,
{
template: { name: "invoice" },
data: data,
},
options
);
let writeStream = response.data.pipe(fs.createWriteStream(path))
.on('finish', () => {
console.log("DONE writing");
return;
});;
} catch (e) {
console.log(e);
}
};
module.exports = router;
However, after deploying the jsreport app to Azure functions, here what's happening:
When I attempt to download my pdf file first time, it downloads fine:
However....when I call the same request for 2nd, 3rd time...etc, the pdf file is being incomplete and of course corrupt (can't open):
Notice how the file size is being smaller in the 2nd and 3rd time.
This is happening only on Azure Functions and not on local, however the reports being downloaded to the temp folder in backend are being fine.
I dunno what I am doing wrong, I feel the may be a delay issue from Azure Functions and sending file before finishing the read stream?
@bjrmatos actually I have changed the whole code, it's working for the backend but i am getting another very weird issuer when sending to client, i will make a new topic
@bjrmatos {"to":"John Lennon","from":"George Harrison","price":800} which is the data example I sent from client.
Is this example code still valid? I am getting the same error, here's my code:
const request = require("request");
const guid = require("guid");
const express = require("express");
const router = express.Router();
const fs = require("fs");
router.use(function (req, res, next) {
// log each request to the console
// continue doing what we were doing and go to the route
next();
});
router.post("/report", async function (req, res) {
let data = req.body.data;
let path = "temp/report.pdf";
const response = await fetchReport(path, data, res);
console.log(response);
});
var fetchReport = async (path, data) => {
let jsr = process.env.JSREPORTURL + "/api/report";
let options = {
'url': jsr, //valid string to report api
'headers': { 'User-Agent': 'request',
'Content-Type': 'application/json' },
'body': JSON.stringify(data),
};
request.post(options).pipe(fs.createWriteStream(path));
};
module.exports = router;