久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

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

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

問題描述

問題對(duì)人有幫助,內(nèi)容完整,我也想知道答案0問題沒有實(shí)際價(jià)值,缺少關(guān)鍵內(nèi)容,沒有改進(jìn)余地

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

<!DOCTYPE html><html><head> <title>express 主頁(yè)</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方法的第一個(gè)參數(shù)

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

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

相關(guān)文章:
主站蜘蛛池模板: 阳城县| 略阳县| 桃园县| 宁远县| 梅河口市| 滨州市| 中牟县| 皋兰县| 巴林左旗| 诸暨市| 高清| 丹棱县| 焦作市| 龙井市| 达尔| 莱西市| 寿阳县| 白城市| 芜湖市| 贞丰县| 北宁市| 五指山市| 湾仔区| 洞头县| 商城县| 冕宁县| 蓝田县| 锡林郭勒盟| 阿勒泰市| 大同市| 土默特左旗| 巫溪县| 红河县| 子长县| 崇仁县| 辽阳市| 萨嘎县| 双峰县| 库伦旗| 延吉市| 三台县|