Download file from url and upload it to AWS S3 without saving - node.js

前端 未结 3 1756
天命终不由人
天命终不由人 2020-12-23 20:52

I\'m writing an application which downloads images from a url and then uploads it to an S3 bucket using the aws-sdk.

Perviously I was just downloading images and sav

3条回答
  •  太阳男子
    2020-12-23 21:25

    This is what I did and works nicely:

    const request = require('request-promise')
    const AWS = require('aws-sdk')
    const s3 = new AWS.S3()
    
    const options = {
        uri: uri,
        encoding: null
    };
    
    async load() {
    
      const body = await request(options)
      
      const uploadResult = await s3.upload({
        Bucket: 'bucket_name',
        Key   : path,
        Body  : body,   
      }).promise()
      
    }

提交回复
热议问题