【问题标题】:NodeJS - reading file from S3 to /tmp folder in LambdaNodeJS - 从 S3 读取文件到 Lambda 中的 /tmp 文件夹
【发布时间】:2019-03-30 04:08:26
【问题描述】:

我需要将 *.dbf 文件从 S3 存储桶移动到 Lambda 中的 /tmp 文件夹以进行进一步处理。到目前为止文件正在移动,但文件内容已损坏,我做错了什么?

exports.getS3Object = ( bucket, key ) => {

  return S3Client.getObject( {

    Bucket              : bucket,
    Key                 : key
  } )
  .promise( )
  .then( file => {

    console.log( 'File loading ', key );
    if ( ! fs.existsSync( '/tmp' ) ) {

      fs.mkdirSync( '/tmp' );
    }
    fs.writeFileSync( '/tmp/' + key, file.Body.toString( 'utf8' ), ( error ) => {

      throw error;  
    } ); 
    return '/tmp/' + key;
  } )
  .catch( error => {

    // file not found
    return error;
  } );
};

【问题讨论】:

    标签: node.js amazon-s3 aws-lambda copy fs


    【解决方案1】:

    您的dbf 文件可能未编码为utf8 字符串。调用file.Body.toString时尝试base64binary编码。

    【讨论】:

      猜你喜欢
      • 2021-04-19
      • 2021-03-18
      • 1970-01-01
      • 2021-09-18
      • 2019-01-16
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 1970-01-01
      相关资源
      最近更新 更多