【问题标题】:Zip file unable to expand after being posted to S3 from SFTP server using node and AWS lambdaZip 文件在使用节点和 AWS lambda 从 SFTP 服务器发布到 S3 后无法展开
【发布时间】:2016-11-02 22:41:25
【问题描述】:

从 sftp 服务器读取压缩文件并将其发布到 S3 后,无法下载和读取文件。尝试解压缩文件时来自控制台的错误如下:

unzip -l 7375_FAIL_test_20160626_185904.txt.zip 
Archive:  7375_FAIL_test_20160626_185904.txt.zip
warning [7375_FAIL_test_20160626_185904.txt.zip]:  4 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [7375_FAIL_test_20160626_185904.txt.zip]:  start of central directory not found;
  zipfile corrupt.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

从sftp读取文件的js代码在这里:

.then(function(fileInfo) {
return sftp.openAsync(dir + '/' + fileInfo.filename, 'r')
.then(function(handle) {
  console.log(fileInfo.attrs.size)
  var result = new Buffer(fileInfo.attrs.size);
  return sftp.readAsync(handle, result, 0, fileInfo.attrs.size, 0)
  .then(function(data) {
    return process(result.toString());
  })
  .then(function(data) {
    return sftp.closeAsync(handle)
    .then(function() {
      return data;
    });
  })

对为什么会发生4 extra bytes at beginning or within zipfile 或如何解决此问题有任何想法吗?

谢谢!

【问题讨论】:

  • 我想做几乎同样的事情。你能和我分享一下 lambda 代码吗?之后我可能会调试并帮助你。
  • process() 是您将代码上传到 S3 的位置吗?如果是这样,您可能不应该在result 上调用.toString()
  • @AkarshSatija 不幸的是,repo 是私有的,但它实际上只是 github.com/gilt/s3-sftp-bridge 的定制版本
  • @robertklep 现在有一个奇怪的问题,即使用 putObject 设置为 s3 的大文件正在以某种方式被修剪,因此 650kb 的文件最终在 s3 中为 638kb。然后,有些文件已损坏,有些则没有。我测试过,在正文中为 s3.putObject 传递的文件大小是正确的大小,因此截断肯定发生在 AWS SDK 过程中。有什么想法吗?
  • @weilandia 我想这取决于该文件如何准确地传输到 S3,如果没有代码很难说问题可能是什么。

标签: node.js amazon-web-services amazon-s3 sftp fs


【解决方案1】:

您可以尝试https://www.cloudzipinc.com/,它将多种不同格式的存档从 S3 扩展为存储桶中的目标前缀,并且可以将 FTP 站点复制到 S3。我用它把数字目录从 FTP 移动到 S3。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-29
    • 2020-05-16
    • 2023-01-27
    • 2020-06-22
    • 2016-12-02
    • 2021-10-01
    • 1970-01-01
    相关资源
    最近更新 更多