file chooser for download appears only after closing node.js
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
html node.js download anchor
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
|
show 1 more comment
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
|
show 1 more comment
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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