简体   繁体   English

将远程映像文件下载到本地文件存储

[英]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执行以下操作

  1. Access the asset Url using the Authorization Bearer token 使用授权承载令牌访问资产网址
  2. Save the file to local file storage. 将文件保存到本地文件存储。

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.

相关问题 如何从云存储中获取文件并作为本地文件处理而无需下载? - How to get file from cloud storage and process as local file without downloading? 使用NodeJS检索远程文件进行存储? - Retrieve remote file with NodeJS for storage? 将API文件下载到Firebase Cloud Storage? - Downloading an API file to Firebase Cloud Storage? 监视远程文件的更改,而无需使用nodejs下载 - Monitor changes of remote file without downloading it with nodejs 下载远程映像会出现错误:stream.js:94错误:ENOENT,打开“路径/到/文件” - Downloading a remote image gives error : stream.js:94 Error: ENOENT, open 'path/to/file' 从本地NodeJS服务器下载视频文件 - Downloading video file from local NodeJS server 将文件从MongoDB下载到本地文件系统 - Downloading a file from MongoDB to local filesystem APP Engine Google Cloud Storage - 下载文件时出现错误 500 - APP Engine Google Cloud Storage - Error 500 when downloading a file 本地存储数据未进入Angularjs的头文件 - Local Storage Data is not getting into header file in Angularjs 如何从本地文件夹(磁盘存储)读取或获取映像文件,并使用nodejs服务器将其发送到Angularjs? - How to read or get image file from local folder(disk storage) and send it to Angularjs using nodejs server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM