国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

node.js下載失敗,求大神解釋

瀏覽:578日期:2024-06-09 10:44:10

問題描述

問題對人有幫助,內容完整,我也想知道答案0問題沒有實際價值,缺少關鍵內容,沒有改進余地

使用express框架下載文件,但是失敗了,直接看代碼

<!DOCTYPE html><html><head> <title>express 主頁</title> <meta charset="utf-8"> <script type="text/javascript" src="jquery.min.js"></script></head><body><div>I love you!</div><button>click there to download a pictutre</button><script type="text/javascript">$(function(){ $('button').click(function(){ $.ajax({url:'/download',type:'get',success:function(result){ alert("Resquest has been received!");} }) })})</script></body></html>以下是node.js代碼 var express = require("express");var app = express();app.use(express.static('public'));app.locals.title = "My app";app.get("/",function(req,res){console.log("resquest has been received!");res.sendFile("public/index.html");res.end();})app.get("/download",function(req,res){res.download('public/example.jpg','example.jpg',function(err){if(err) console.log(err);else console.log("download successfully"); });})app.listen(3000);console.log("OK");

node.js下載失敗,求大神解釋

求解疑

問題解答

回答1:

你的下載按鈕我建議直接寫成

下載

注意res.download方法的第一個參數

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. }});

然后你的圖片雖然尺寸很大,但是太模糊了。。。

相關文章:
主站蜘蛛池模板: 临安市| 文成县| 漳州市| 怀仁县| 临夏市| 岢岚县| 万荣县| 惠州市| 台湾省| 怀集县| 兴和县| 长丰县| 土默特左旗| 锦屏县| 砀山县| 莎车县| 阳谷县| 延安市| 南丰县| 瓮安县| 黄山市| 远安县| 宜兰市| 澄江县| 棋牌| 隆尧县| 太湖县| 阿尔山市| 保定市| 日喀则市| 桐梓县| 龙游县| 红桥区| 神木县| 上林县| 荃湾区| 衡阳市| 临泽县| 大庆市| 阳谷县| 潍坊市|