简体   繁体   English

如何使用ruby从s3存储桶下载zip文件

[英]how to download a zip file from s3 bucket using ruby

i am able to zip all required files(using ruby gems of AWS SDK) & upload them to the S3 bucket. 我能够压缩所有必需的文件(使用AWS开发工具包的ruby gem)并将其上传到S3存储桶。 when i tried to download the zip files from S3 to local server & unzip them , i am geeting following error... 当我尝试将zip文件从S3下载到本地服务器并解压缩它们时,我正在跟踪以下错误...

[2013-05-06T07:19:37+00:00] FATAL: TypeError: aws_unzip[db_unzip] (aws::unzip line 14) had an error: TypeError: can't dup NilClass [2013-05-06T07:19:37 + 00:00]严重:TypeError:aws_unzip [db_unzip](aws :: unzip第14行)出现错误:TypeError:无法重复NilClass

Even when i try to unzip manually, i can see "zip files is corrupted"...But the zip file which is present in S3 location is not corrupted(i tested to extract them manually by downloading them, it extracted well).... Can any one help where i am doing mistake in reading zip files from bucket to local server????? 即使当我尝试手动解压缩时,我也可以看到“ zip文件已损坏” ...但是S3位置中存在的zip文件并未损坏(我测试过通过下载手动提取它们,提取得很好)。 ..在从存储桶读取zip文件到本地服务器时我做错了的任何人都可以帮忙吗? When downloading it is getting corrupted... 下载时它已损坏...

My code is 我的代码是

File.open(dd, 'w') {|f| f.write(obj.read.force_encoding('utf-8'))}

Try 'wb' mode - zip is a binary file. 尝试使用“ wb”模式-zip是二进制文件。 Also that force_encoding is very suspicious. 另外,force_encoding非常可疑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM