cari

Rumah  >  Soal Jawab  >  teks badan

node.js - nodejs如何发送请求excel文件并下载

PHP中文网PHP中文网2786 hari yang lalu456

membalas semua(1)saya akan balas

  • ringa_lee

    ringa_lee2017-04-17 15:37:11

    res.download(path [, filename] [, fn]) http://expressjs.com/en/api.h...

    Transfers the file at path as an “attachment”. Typically, browsers will prompt the user for download. By default, the Content-Disposition header “filename=” parameter is path (this typically appears in the browser dialog). Override this default with the filename parameter.

    When an error ocurrs or transfer is complete, the method calls the optional callback function fn. This method uses res.sendFile() to transfer the file.

    res.download('/report-12345.pdf');
    
    res.download('/report-12345.pdf', 'report.pdf');
    
    res.download('/report-12345.pdf', 'report.pdf', function(err){
      if (err) {
        // Handle error, but keep in mind the response may be partially-sent
        // so check res.headersSent
      } else {
        // decrement a download credit, etc.
      }
    });

    balas
    0
  • Batalbalas