How to implement a file download with Node.js's fs module and express

前端 未结 2 1263
再見小時候
再見小時候 2021-02-15 16:42

Because the file should be generated dynamically, maybe I should use the fs modules\'s writeStream. But I couldn\'t find any example codes with my poor googling. Sorry.

2条回答
  •  爱一瞬间的悲伤
    2021-02-15 16:57

    you don't need fs, just stream your data from db in request handler

    you can set file metadata using Content-Disposition header

    Content-Type: image/jpeg
    Content-Disposition: attachment; filename=genome.jpeg; 
      modification-date="Wed, 12 Feb 1997 16:29:51 -0500";
    Content-Description: a complete map of the human genome
    

提交回复
热议问题