mschilli / net-google-drive-simple

Net::Google::Drive::Simple CPAN Module
Other
11 stars 22 forks source link

files cut 1 byte short on upload? #2

Closed xrmb closed 11 years ago

xrmb commented 11 years ago

I wrote a little script that uploads 100 files 100 bytes in size. When I go to the google drive website many of them are only 99 bytes. I tried to debug the issue but could not find anything.

mschilli commented 11 years ago

Interesting, I've never experienced such an error, can you post your test script to let me debug it?

xrmb commented 11 years ago

I traced it down, it is this line: my $file_data = slurp $file;

the slurp does not handle binary files correctly, replacing it with something like my $fh; open($fh, '<', $file); binmode($fh); my $file_data; read($fh, $file_data, -s $file); close($file);

makes it work... well, some error handling should be added or slurp fixed.

this script: use Net::Google::Drive::Simple;

use Log::Log4perl qw(:easy); Log::Log4perl->easy_init($DEBUG);

my $gd = Net::Google::Drive::Simple->new(config_file => 'google-drive.yml'); my (undef, $r) = $gd->children('/'); $gd->file_upload('a.png', $r);

spits out this: 2013/03/15 08:34:53 Read (91)[.PNG.......IHDR...d...d...[snip=39].Q@O...x...b.t....IEND.B`.] from a.png

where a.png is (lets hope github imges dont get modified): a

edit: looks like github keeps my original, it is 92 bytes

mschilli commented 11 years ago

Nice find! Which OS are you running your application on, Windows by any chance?

xrmb commented 11 years ago

Yes, Windows (unfortunately). Will have to use CPAN, which is a pain, to get any updates from you. ActiveState is really slow updating ppm. At least they have your modules :)

But besides this little issue and google drive api being slow and loves error 500, it runs very smooth and stable.

mschilli commented 11 years ago

I've made the fix in the Sysadm::Install module that provides the slurp() function: http://perlmeister.com/tmp/sysadm-install-0.43.tgz Would you be able to download the tarball from there, install the module and let me know if it fixes the problem?

xrmb commented 11 years ago

It works, tried with text and binary files of different sizes.

mschilli commented 11 years ago

On Fri, 15 Mar 2013, xrmb wrote:

Yes, Windows (unfortunately). Will have to use CPAN, which is a pain, to get any updates from you. ActiveState is really slow updating ppm. At least they have your modules :)

Okay, Sysadm::Install 0.43 is on CPAN now, might be a while until Activestate picks it up, but feel free to download/install!

-- Mike

Mike Schilli m@perlmeister.com

xrmb commented 11 years ago

I updated it via CPAN, worked fine. ActiveState is still at 0.40.