您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> Web开发 >> (ajax)axios处理stream返回结果 用fscreateWriteStream+pipe不能写入文件

(ajax)axios处理stream返回结果 用fscreateWriteStream+pipe不能写入文件

来源:网络整理     时间:2018/1/29 0:56:09     关键词:

关于网友提出的“ (ajax)axios处理stream返回结果 用fscreateWriteStream+pipe不能写入文件”问题疑问,本网通过在网上对“ (ajax)axios处理stream返回结果 用fscreateWriteStream+pipe不能写入文件”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题: (ajax)axios处理stream返回结果 用fscreateWriteStream+pipe不能写入文件
描述:

axios({
        method: 'get',
        url: `https://${serverUrl}/download/`,
        responseType: 'stream'
     })
     .then(function(response) {
         const rs = response.data
         const ws = fs.createWriteStream('/tmp/update_files.tar.gz')
         rs.pipe(ws)
     })

这样处理并不能写入数据文件,请问下axios怎么处理stream返回结果


解决方案1:

const fs = require('fs');
const axios = require('axios');

axios({
        method: 'get',
        url: `https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1513166971517&di=d4429abd2c482195090a666937bb3aa1&imgtype=0&src=http%3A%2F%2Fpic20.photophoto.cn%2F20110925%2F0010023291781194_b.jpg`,
        responseType: 'stream'
    })
    .then(function(response) {
        const rs = response.data
        const ws = fs.createWriteStream('./1.jpg')
        rs.pipe(ws)
    });

好像没什么问题,是不是权限问题,有错误信息吗?


以上介绍了“ (ajax)axios处理stream返回结果 用fscreateWriteStream+pipe不能写入文件”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/4537114.html

相关图片

相关文章