3

我正在使用 node.js 和 knox 的 putFile 将 zip 文件上传到 S3。原始 zip 可以正常打开,从 S3 下载的 zip 已损坏。

这是我正在使用的相关代码:

var client = knox.createClient({
    key: 'MY KEY HERE', 
    secret: 'MY SECRET HERE', 
    bucket: 'MY BUCKET HERE'
});

var filename = 'example.zip';

var req = client.putFile(filename, filename, { 'x-amz-acl': 'public-read' }, function(err, res){
    if (res.statusCode == 200) {
        console.log('moved '+filename+' to s3');
    }
    else {
        console.log('failed to move to s3');
    }
});

这是我尝试在 OSX 的终端中使用 zip 修复 zip 文件时得到的输出

> zip -F remote.zip --out fixed-remote.zip
Fix archive (-F) - assume mostly intact archive
zip warning: bad archive - missing end signature
zip warning: (If downloaded, was binary mode used?  If not, the
zip warning:  archive may be scrambled and not recoverable)
zip warning: Can't use -F to fix (try -FF)
zip error: Zip file structure invalid (remote.zip)

> zip -FF remote.zip --out fixed-remote.zip
zip warning: Missing end (EOCDR) signature - either this archive is not readable or the end is damaged
> Is this a single-disk archive?  (y/n): y
Assuming single-disk archive
[LISTS ALL FILES COPIED HERE]
zip warning: no end of stream entry found: awesome-file.jpg
zip warning: rewinding and scanning for later entries

我完全不知道为什么会发生这种情况。几乎似乎最后几个字节不是由 knox 发送的,但这完全是新手的猜测。

有人有想法么?

更新:

我认为这可能是生成 ZIP 文件而不是上传的问题。我尝试上传由 OSX Zip Utility 生成的 zip 文件,每次都能正常工作。我将对此进行更深入的研究。谢谢您的帮助。

4

1 回答 1

2

在未明确指定区域选项的情况下,putFile 和 putStream 等便利 API 目前无法在美国标准以外的区域中按预期使用存储桶。

确保添加您的区域: https ://github.com/LearnBoost/knox#region

var client = knox.createClient({
    key: 'MY KEY HERE', 
    secret: 'MY SECRET HERE', 
    bucket: 'MY BUCKET HERE',
    region: 'us-standard'
});

似乎工作?文件大小对我来说是相同的: 输出:

node aws.js 
{ Name: 'MYBUCKET',
  Prefix: '',
  Marker: '',
  MaxKeys: 1000,
  IsTruncated: false,
  Contents: 
   [ { Key: 'hudson_out.jpg',
       LastModified: Wed May 29 2013 12:38:50 GMT-0400 (EDT),
       ETag: '"996f46db285c900f3e1596d484a72fb4"',
       Size: 1690706,
       Owner: [Object],
       StorageClass: 'STANDARD' } ] }
moved hudson_out.jpg to s3

ls -la hudson_out.jpg -rw-r--r--@ 1 (stuff) 1690706 2012 年 8 月 31 日 hudson_out.jpg

于 2013-05-29T16:42:22.253 回答