Dheeraj Gundra
Dheeraj Gundra

Reputation: 1755

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. when i tried to download the zip files from S3 to local server & unzip them , i am geeting following error...

[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

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????? When downloading it is getting corrupted...

My code is

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

Upvotes: 1

Views: 2159

Answers (1)

pguardiario
pguardiario

Reputation: 54984

Try 'wb' mode - zip is a binary file. Also that force_encoding is very suspicious.

Upvotes: 2

Related Questions