基於thinkjs 3.x 轉發下載圖片 示例

需求:通過thinkjs的action,轉發下載指定url的文件。

簡單示例:


    public async nuonuofpAction() {
            const PassThrough = require('stream').PassThrough;
            this.body = request.get('https://thinkjs.org/static/img/new/logo.png')
                .on('response', (response) => {
                    let keys = Object.keys(response.headers);
                    for (let key of keys) {
                        this.ctx.set(key, response.headers[key]);
                    }
                })
                .on('error', this.ctx.onerror)
                .pipe(PassThrough());
            return;
   }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章