When downloading zip file from linux server with node and angular 5,zip file successfully downloads but EMPTY
In my services.service.ts file I am passing a name of a zip and calling the route
services.service.ts
downloadFile(name)
console.log(name);
let newName = name+".zip";
console.log(newName);
return this.http
.get(`/services/downloadFile/$name`,
responseType: ResponseContentType.Blob )
.pipe(map(res =>
return
filename: newName,
data: res.blob()
;
))
.subscribe(res =>
// console.log('start download:',res);
var url = window.URL.createObjectURL(res.data);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = url;
a.download = res.filename;
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
, error =>
console.log('download error:', JSON.stringify(error));
, () =>
console.log('Completed file download.')
);
After i call this route from service.js the zip file gets downloaded to windows but with no data
service.js
router.get('/downloadFile/:name', function (req, res)
let name = req.params.name;
let newName = name+".zip";
res.download(`./config/$newName`, newName, function (err)
if (err)
console.log(err);
console.log("ERROR APPEARED");
else
console.log('file uploaded :)');
);
);
This code executes with no errors (I will get "file uploaded :)" in a console) but the downloaded zip I wont be able to open or extract because it will not contain data (appropriate data)
node.js angular
add a comment |
In my services.service.ts file I am passing a name of a zip and calling the route
services.service.ts
downloadFile(name)
console.log(name);
let newName = name+".zip";
console.log(newName);
return this.http
.get(`/services/downloadFile/$name`,
responseType: ResponseContentType.Blob )
.pipe(map(res =>
return
filename: newName,
data: res.blob()
;
))
.subscribe(res =>
// console.log('start download:',res);
var url = window.URL.createObjectURL(res.data);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = url;
a.download = res.filename;
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
, error =>
console.log('download error:', JSON.stringify(error));
, () =>
console.log('Completed file download.')
);
After i call this route from service.js the zip file gets downloaded to windows but with no data
service.js
router.get('/downloadFile/:name', function (req, res)
let name = req.params.name;
let newName = name+".zip";
res.download(`./config/$newName`, newName, function (err)
if (err)
console.log(err);
console.log("ERROR APPEARED");
else
console.log('file uploaded :)');
);
);
This code executes with no errors (I will get "file uploaded :)" in a console) but the downloaded zip I wont be able to open or extract because it will not contain data (appropriate data)
node.js angular
add a comment |
In my services.service.ts file I am passing a name of a zip and calling the route
services.service.ts
downloadFile(name)
console.log(name);
let newName = name+".zip";
console.log(newName);
return this.http
.get(`/services/downloadFile/$name`,
responseType: ResponseContentType.Blob )
.pipe(map(res =>
return
filename: newName,
data: res.blob()
;
))
.subscribe(res =>
// console.log('start download:',res);
var url = window.URL.createObjectURL(res.data);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = url;
a.download = res.filename;
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
, error =>
console.log('download error:', JSON.stringify(error));
, () =>
console.log('Completed file download.')
);
After i call this route from service.js the zip file gets downloaded to windows but with no data
service.js
router.get('/downloadFile/:name', function (req, res)
let name = req.params.name;
let newName = name+".zip";
res.download(`./config/$newName`, newName, function (err)
if (err)
console.log(err);
console.log("ERROR APPEARED");
else
console.log('file uploaded :)');
);
);
This code executes with no errors (I will get "file uploaded :)" in a console) but the downloaded zip I wont be able to open or extract because it will not contain data (appropriate data)
node.js angular
In my services.service.ts file I am passing a name of a zip and calling the route
services.service.ts
downloadFile(name)
console.log(name);
let newName = name+".zip";
console.log(newName);
return this.http
.get(`/services/downloadFile/$name`,
responseType: ResponseContentType.Blob )
.pipe(map(res =>
return
filename: newName,
data: res.blob()
;
))
.subscribe(res =>
// console.log('start download:',res);
var url = window.URL.createObjectURL(res.data);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = url;
a.download = res.filename;
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
, error =>
console.log('download error:', JSON.stringify(error));
, () =>
console.log('Completed file download.')
);
After i call this route from service.js the zip file gets downloaded to windows but with no data
service.js
router.get('/downloadFile/:name', function (req, res)
let name = req.params.name;
let newName = name+".zip";
res.download(`./config/$newName`, newName, function (err)
if (err)
console.log(err);
console.log("ERROR APPEARED");
else
console.log('file uploaded :)');
);
);
This code executes with no errors (I will get "file uploaded :)" in a console) but the downloaded zip I wont be able to open or extract because it will not contain data (appropriate data)
node.js angular
node.js angular
asked Nov 16 '18 at 9:12
NullPointerExceptionNullPointerException
534
534
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
I've encountered a similar problem once - In case you use token-based auth you probably forgot to add these in your headers, try:
.get(`/services/downloadFile/$name`, headers: new Headers(
'Content-Type': 'application/json', // INFO: Format set to JSON
'authorization': yourAuth.token.etc // INFO: Attach token
),responseType: ResponseContentType.Blob )
Hope that helps to you solve your issue..
Thanks,works like charm :D
– NullPointerException
Nov 16 '18 at 12:18
add a comment |
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%2f53334663%2fwhen-downloading-zip-file-from-linux-server-with-node-and-angular-5-zip-file-suc%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I've encountered a similar problem once - In case you use token-based auth you probably forgot to add these in your headers, try:
.get(`/services/downloadFile/$name`, headers: new Headers(
'Content-Type': 'application/json', // INFO: Format set to JSON
'authorization': yourAuth.token.etc // INFO: Attach token
),responseType: ResponseContentType.Blob )
Hope that helps to you solve your issue..
Thanks,works like charm :D
– NullPointerException
Nov 16 '18 at 12:18
add a comment |
I've encountered a similar problem once - In case you use token-based auth you probably forgot to add these in your headers, try:
.get(`/services/downloadFile/$name`, headers: new Headers(
'Content-Type': 'application/json', // INFO: Format set to JSON
'authorization': yourAuth.token.etc // INFO: Attach token
),responseType: ResponseContentType.Blob )
Hope that helps to you solve your issue..
Thanks,works like charm :D
– NullPointerException
Nov 16 '18 at 12:18
add a comment |
I've encountered a similar problem once - In case you use token-based auth you probably forgot to add these in your headers, try:
.get(`/services/downloadFile/$name`, headers: new Headers(
'Content-Type': 'application/json', // INFO: Format set to JSON
'authorization': yourAuth.token.etc // INFO: Attach token
),responseType: ResponseContentType.Blob )
Hope that helps to you solve your issue..
I've encountered a similar problem once - In case you use token-based auth you probably forgot to add these in your headers, try:
.get(`/services/downloadFile/$name`, headers: new Headers(
'Content-Type': 'application/json', // INFO: Format set to JSON
'authorization': yourAuth.token.etc // INFO: Attach token
),responseType: ResponseContentType.Blob )
Hope that helps to you solve your issue..
answered Nov 16 '18 at 12:14
iLuvLogixiLuvLogix
1,629726
1,629726
Thanks,works like charm :D
– NullPointerException
Nov 16 '18 at 12:18
add a comment |
Thanks,works like charm :D
– NullPointerException
Nov 16 '18 at 12:18
Thanks,works like charm :D
– NullPointerException
Nov 16 '18 at 12:18
Thanks,works like charm :D
– NullPointerException
Nov 16 '18 at 12:18
add a comment |
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.
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%2f53334663%2fwhen-downloading-zip-file-from-linux-server-with-node-and-angular-5-zip-file-suc%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