How does nodejs add header? to this url before jumping to another url

I want to download directly when I open a link. By default, opening a link will automatically open a preview in the browser. Can nodejs add header to the url before opening the link?

exports.download = async (ctx,next) => {
    ctx.type = "application/octet-stream"
    ctx.set("Content-Disposition","attachment;filename=name")//
    ctx.redirect(ctx.request.query.path) //
}

I am currently using redirects without adding this header.
if I write this url in a route in iframe form, what I download is the code for the iframe tag.

Mar.18,2021
  • Express routing problem

    I am a novice. I have just come into contact with the node.js and express frameworks. I have configured routing according to the online tutorial, but there are some problems, as follows: first of all, the file structure is as follows: index.js:...

Menu