file chooser for download appears only after closing node.js












0














I have a very simple node.js app which successfully processes a file (from formidable form) but the download of the result file fails. The download html



<p><input type="text" value = "tx-AllSerums.xlsx"><br>
<a href="/transformed/tx-AllSerums.xlsx"
download="All Serums.xlsx">Download transformed file</a>
</p>



The result files are written to the directory structure from where I run node (the 'transformed' dir is in the dir in which I run node).
When I click on the above href I get console output but no file save dialog. (Should the server even get this event?)
When I kill the node server, up pops the file save dialog. Of course the save fails: Network error.
I'm currently running everything on my workstation: Ubuntu 18.04; Chrome 70.0.3538.77, node v10.13.0



I've found that the file save dialog does appear but a very long time after the click. But the server is still up and the save operation still fails: Network error.



Adding res.end() to the block catching the download click gets the dialog up immediately. Now I successfully download a zero length file. Oddly I find that encouraging.



var formidable = require('formidable');
var util = require("util");
var http = require('http');
var url = require('url');
var fs = require('fs');
var java = require("java");
var proc = require("process");

java.classpath.push("/home/u0138544/fake/prep-1.jar");
java.classpath.push("/home/u0138544/fake/SRTDependancies-1.jar");
console.log(proc.cwd());
http.createServer(function (req, res) {
txName = "";
if (req.url == '/fileupload' && req.method.toLowerCase() == 'post') {
var form = formidable.IncomingForm();
form.keepExtensions = true;
var excelFilePath;
var origName;
form.parse(req , function (err, fields, files) {
excelFilePath = files.filetoupload.path;
console.log("upload " + excelFilePath);
origName = files.filetoupload.name;
txName = "tx-" + origName.replace(/s/g, "");
console.log( "txname = " + txName);
//just for formatter
var clz = "edu.utah.camplab.xlsx.SampleReportTransformer";
var tx = java.newInstanceSync(clz);
java.callMethodSync(tx, "run", excelFilePath, "./transformed/" + txName);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<p>');
res.write('<input type="text" value = "' + txName +'"><br>');
res.write('<a href="transformed/' + txName + '" download="' + origName +'">Download transformed file</a></p>');
return res.end();
});
}
else if (req.url.includes('transformed') &&
req.method.toLowerCase() == 'get') {
console.log("download attribute doesn't work")
res.end();
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
res.write('<input type="file" name="filetoupload" label="Pick a file"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();
}
}).listen(15080);









share|improve this question
























  • Can you post your node code?
    – Phix
    Nov 14 '18 at 19:47










  • @Phix: I certainly would be the SO formatter is giving me grief. I may have to post an "answer"
    – rjs
    Nov 14 '18 at 22:40










  • ^would be^would but^. Finally got the quotes right.
    – rjs
    Nov 14 '18 at 23:00












  • Hmm, I've never used java in node before, but I would suggest looking at using express to help with some of this.
    – Phix
    Nov 15 '18 at 1:42










  • The java part works: input files are correctly transformed and written to the "transformed" dir. I'm loath to add another module in fear of making this node stuff an even blacker box. ;) What would be the immediate point/benefit of adding express?
    – rjs
    Nov 15 '18 at 16:44
















0














I have a very simple node.js app which successfully processes a file (from formidable form) but the download of the result file fails. The download html



<p><input type="text" value = "tx-AllSerums.xlsx"><br>
<a href="/transformed/tx-AllSerums.xlsx"
download="All Serums.xlsx">Download transformed file</a>
</p>



The result files are written to the directory structure from where I run node (the 'transformed' dir is in the dir in which I run node).
When I click on the above href I get console output but no file save dialog. (Should the server even get this event?)
When I kill the node server, up pops the file save dialog. Of course the save fails: Network error.
I'm currently running everything on my workstation: Ubuntu 18.04; Chrome 70.0.3538.77, node v10.13.0



I've found that the file save dialog does appear but a very long time after the click. But the server is still up and the save operation still fails: Network error.



Adding res.end() to the block catching the download click gets the dialog up immediately. Now I successfully download a zero length file. Oddly I find that encouraging.



var formidable = require('formidable');
var util = require("util");
var http = require('http');
var url = require('url');
var fs = require('fs');
var java = require("java");
var proc = require("process");

java.classpath.push("/home/u0138544/fake/prep-1.jar");
java.classpath.push("/home/u0138544/fake/SRTDependancies-1.jar");
console.log(proc.cwd());
http.createServer(function (req, res) {
txName = "";
if (req.url == '/fileupload' && req.method.toLowerCase() == 'post') {
var form = formidable.IncomingForm();
form.keepExtensions = true;
var excelFilePath;
var origName;
form.parse(req , function (err, fields, files) {
excelFilePath = files.filetoupload.path;
console.log("upload " + excelFilePath);
origName = files.filetoupload.name;
txName = "tx-" + origName.replace(/s/g, "");
console.log( "txname = " + txName);
//just for formatter
var clz = "edu.utah.camplab.xlsx.SampleReportTransformer";
var tx = java.newInstanceSync(clz);
java.callMethodSync(tx, "run", excelFilePath, "./transformed/" + txName);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<p>');
res.write('<input type="text" value = "' + txName +'"><br>');
res.write('<a href="transformed/' + txName + '" download="' + origName +'">Download transformed file</a></p>');
return res.end();
});
}
else if (req.url.includes('transformed') &&
req.method.toLowerCase() == 'get') {
console.log("download attribute doesn't work")
res.end();
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
res.write('<input type="file" name="filetoupload" label="Pick a file"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();
}
}).listen(15080);









share|improve this question
























  • Can you post your node code?
    – Phix
    Nov 14 '18 at 19:47










  • @Phix: I certainly would be the SO formatter is giving me grief. I may have to post an "answer"
    – rjs
    Nov 14 '18 at 22:40










  • ^would be^would but^. Finally got the quotes right.
    – rjs
    Nov 14 '18 at 23:00












  • Hmm, I've never used java in node before, but I would suggest looking at using express to help with some of this.
    – Phix
    Nov 15 '18 at 1:42










  • The java part works: input files are correctly transformed and written to the "transformed" dir. I'm loath to add another module in fear of making this node stuff an even blacker box. ;) What would be the immediate point/benefit of adding express?
    – rjs
    Nov 15 '18 at 16:44














0












0








0







I have a very simple node.js app which successfully processes a file (from formidable form) but the download of the result file fails. The download html



<p><input type="text" value = "tx-AllSerums.xlsx"><br>
<a href="/transformed/tx-AllSerums.xlsx"
download="All Serums.xlsx">Download transformed file</a>
</p>



The result files are written to the directory structure from where I run node (the 'transformed' dir is in the dir in which I run node).
When I click on the above href I get console output but no file save dialog. (Should the server even get this event?)
When I kill the node server, up pops the file save dialog. Of course the save fails: Network error.
I'm currently running everything on my workstation: Ubuntu 18.04; Chrome 70.0.3538.77, node v10.13.0



I've found that the file save dialog does appear but a very long time after the click. But the server is still up and the save operation still fails: Network error.



Adding res.end() to the block catching the download click gets the dialog up immediately. Now I successfully download a zero length file. Oddly I find that encouraging.



var formidable = require('formidable');
var util = require("util");
var http = require('http');
var url = require('url');
var fs = require('fs');
var java = require("java");
var proc = require("process");

java.classpath.push("/home/u0138544/fake/prep-1.jar");
java.classpath.push("/home/u0138544/fake/SRTDependancies-1.jar");
console.log(proc.cwd());
http.createServer(function (req, res) {
txName = "";
if (req.url == '/fileupload' && req.method.toLowerCase() == 'post') {
var form = formidable.IncomingForm();
form.keepExtensions = true;
var excelFilePath;
var origName;
form.parse(req , function (err, fields, files) {
excelFilePath = files.filetoupload.path;
console.log("upload " + excelFilePath);
origName = files.filetoupload.name;
txName = "tx-" + origName.replace(/s/g, "");
console.log( "txname = " + txName);
//just for formatter
var clz = "edu.utah.camplab.xlsx.SampleReportTransformer";
var tx = java.newInstanceSync(clz);
java.callMethodSync(tx, "run", excelFilePath, "./transformed/" + txName);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<p>');
res.write('<input type="text" value = "' + txName +'"><br>');
res.write('<a href="transformed/' + txName + '" download="' + origName +'">Download transformed file</a></p>');
return res.end();
});
}
else if (req.url.includes('transformed') &&
req.method.toLowerCase() == 'get') {
console.log("download attribute doesn't work")
res.end();
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
res.write('<input type="file" name="filetoupload" label="Pick a file"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();
}
}).listen(15080);









share|improve this question















I have a very simple node.js app which successfully processes a file (from formidable form) but the download of the result file fails. The download html



<p><input type="text" value = "tx-AllSerums.xlsx"><br>
<a href="/transformed/tx-AllSerums.xlsx"
download="All Serums.xlsx">Download transformed file</a>
</p>



The result files are written to the directory structure from where I run node (the 'transformed' dir is in the dir in which I run node).
When I click on the above href I get console output but no file save dialog. (Should the server even get this event?)
When I kill the node server, up pops the file save dialog. Of course the save fails: Network error.
I'm currently running everything on my workstation: Ubuntu 18.04; Chrome 70.0.3538.77, node v10.13.0



I've found that the file save dialog does appear but a very long time after the click. But the server is still up and the save operation still fails: Network error.



Adding res.end() to the block catching the download click gets the dialog up immediately. Now I successfully download a zero length file. Oddly I find that encouraging.



var formidable = require('formidable');
var util = require("util");
var http = require('http');
var url = require('url');
var fs = require('fs');
var java = require("java");
var proc = require("process");

java.classpath.push("/home/u0138544/fake/prep-1.jar");
java.classpath.push("/home/u0138544/fake/SRTDependancies-1.jar");
console.log(proc.cwd());
http.createServer(function (req, res) {
txName = "";
if (req.url == '/fileupload' && req.method.toLowerCase() == 'post') {
var form = formidable.IncomingForm();
form.keepExtensions = true;
var excelFilePath;
var origName;
form.parse(req , function (err, fields, files) {
excelFilePath = files.filetoupload.path;
console.log("upload " + excelFilePath);
origName = files.filetoupload.name;
txName = "tx-" + origName.replace(/s/g, "");
console.log( "txname = " + txName);
//just for formatter
var clz = "edu.utah.camplab.xlsx.SampleReportTransformer";
var tx = java.newInstanceSync(clz);
java.callMethodSync(tx, "run", excelFilePath, "./transformed/" + txName);
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<p>');
res.write('<input type="text" value = "' + txName +'"><br>');
res.write('<a href="transformed/' + txName + '" download="' + origName +'">Download transformed file</a></p>');
return res.end();
});
}
else if (req.url.includes('transformed') &&
req.method.toLowerCase() == 'get') {
console.log("download attribute doesn't work")
res.end();
}
else {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
res.write('<input type="file" name="filetoupload" label="Pick a file"><br>');
res.write('<input type="submit">');
res.write('</form>');
return res.end();
}
}).listen(15080);






html node.js download anchor






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 23:21









Phix

4,42621845




4,42621845










asked Nov 14 '18 at 19:42









rjs

185




185












  • Can you post your node code?
    – Phix
    Nov 14 '18 at 19:47










  • @Phix: I certainly would be the SO formatter is giving me grief. I may have to post an "answer"
    – rjs
    Nov 14 '18 at 22:40










  • ^would be^would but^. Finally got the quotes right.
    – rjs
    Nov 14 '18 at 23:00












  • Hmm, I've never used java in node before, but I would suggest looking at using express to help with some of this.
    – Phix
    Nov 15 '18 at 1:42










  • The java part works: input files are correctly transformed and written to the "transformed" dir. I'm loath to add another module in fear of making this node stuff an even blacker box. ;) What would be the immediate point/benefit of adding express?
    – rjs
    Nov 15 '18 at 16:44


















  • Can you post your node code?
    – Phix
    Nov 14 '18 at 19:47










  • @Phix: I certainly would be the SO formatter is giving me grief. I may have to post an "answer"
    – rjs
    Nov 14 '18 at 22:40










  • ^would be^would but^. Finally got the quotes right.
    – rjs
    Nov 14 '18 at 23:00












  • Hmm, I've never used java in node before, but I would suggest looking at using express to help with some of this.
    – Phix
    Nov 15 '18 at 1:42










  • The java part works: input files are correctly transformed and written to the "transformed" dir. I'm loath to add another module in fear of making this node stuff an even blacker box. ;) What would be the immediate point/benefit of adding express?
    – rjs
    Nov 15 '18 at 16:44
















Can you post your node code?
– Phix
Nov 14 '18 at 19:47




Can you post your node code?
– Phix
Nov 14 '18 at 19:47












@Phix: I certainly would be the SO formatter is giving me grief. I may have to post an "answer"
– rjs
Nov 14 '18 at 22:40




@Phix: I certainly would be the SO formatter is giving me grief. I may have to post an "answer"
– rjs
Nov 14 '18 at 22:40












^would be^would but^. Finally got the quotes right.
– rjs
Nov 14 '18 at 23:00






^would be^would but^. Finally got the quotes right.
– rjs
Nov 14 '18 at 23:00














Hmm, I've never used java in node before, but I would suggest looking at using express to help with some of this.
– Phix
Nov 15 '18 at 1:42




Hmm, I've never used java in node before, but I would suggest looking at using express to help with some of this.
– Phix
Nov 15 '18 at 1:42












The java part works: input files are correctly transformed and written to the "transformed" dir. I'm loath to add another module in fear of making this node stuff an even blacker box. ;) What would be the immediate point/benefit of adding express?
– rjs
Nov 15 '18 at 16:44




The java part works: input files are correctly transformed and written to the "transformed" dir. I'm loath to add another module in fear of making this node stuff an even blacker box. ;) What would be the immediate point/benefit of adding express?
– rjs
Nov 15 '18 at 16:44












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307684%2ffile-chooser-for-download-appears-only-after-closing-node-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53307684%2ffile-chooser-for-download-appears-only-after-closing-node-js%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

鏡平學校

ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

Why https connections are so slow when debugging (stepping over) in Java?