[英]Downloading a remote image file to local file storage
I'm having trouble downloading a remote file using node js. 我在使用节点js下载远程文件时遇到问题。
The file is a large image and can only be accessed using an api request and authorization header. 该文件是大图像,只能使用api请求和授权标头访问。
I need to use node js to do the following 我需要使用节点js执行以下操作
How can I do that using node js? 如何使用Node JS做到这一点?
I tried doing 我试着做
request.get({url: aurl, encoding: "binary"}).pipe(fs.writeFileSync('./marvel-web/dist/images/image_9.png'));
I'm missing the Authorization header. 我缺少授权标头。
I also want to do all of this synchronously not async. 我也想同步而不是异步执行所有这些操作。
If you want the authorization to be set, in the options object of request, put: 如果要设置授权,请在请求的选项对象中输入:
{
url: aurl,
encoding: "binary,
headers: {
Authorization: "Bearer" + token,
}
}
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.