我正在使用 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 文件,每次都能正常工作。我将对此进行更深入的研究。谢谢您的帮助。