Net::UpYun - Simple client library for UpYun Restful API.
# Yes, I love modern perl! use v5.12; use Net::UpYun; my $upyun = Net::UpYun->new( bucket_account => 'xxxxx', bucket_password => 'xxxx', bucket => 'bucket_name', # optional api_domain => 'http://v0.api.upyun.com', ); # get bucket/folder/file usage my $usage = $upyun->usage; # or folder/file say $upyun->usage('/demo'); # switch bucket $upyun->use_bucket('bucket_new'); # use different account/password $upyun->use_bucket('bucket_new',$new_account,$new_password); # create dir my $ok = $upyun->mkdir('/demo2'); # list file under the directory my $files = $upyun->list('/demo2'); # rm dir my $ok = $upyun->rmdir('/demo2'); # upload file my $ok = $upyun->put($file_key,$file_bytes); # get file content my $bytes = $upyun->get($file_key); # delete file $upyun->delete($file_key); # change api domaim $upyun->api_domain('http://v1.api.upyun.com');
This module provides very simple interfaces to UpYun Cloud servie,for more details about UpYun storage/CDN clound service, see http://www.upyun.com/.
This module uses WWW::Curl and libcurl for best performance, I just test on Mac Lion and Linux, maybe works on Windows/Cygwin.
# whole bucket used storage $upyun->usage; # some dir/folder say $upyun->usage('/dir1'); # some file size say $upyun->usage('/dir1/demo1.jpg');
List bucket or path(folder or file) used space.
# switch to new bucket,account/password same as current $upyun->use_bucket('bucket2'); # switch to new bucket, also set new account/password $upyun->use_bucket('bucket3','new_user','new_password');
Switch to another bucket, if omit new_account,new_password, use previous defined.
my $ok = $upyun->mkdir('/path1/path2');
Build directory or path.
my $ok = $upyun->rmdir('/path1');
Delete the directory, it must be empty.
my $dir_content_str = $upyun->list('/');
List files under the directory.
TODO: $dir_content_str is plain text, need to parse.
# it will auto mkdir. my $ok = $upyun->put('/demo/1.txt','okokok');
Upload content to the file, it will auto create directories.
NOTE: According UpYun note, max directories deep level is limited to 10, be careful.
say $upyun->get('/demo/1.txt');
Get the file content.
my $ok = $upyun->delete('/demo/1.txt');
Delete the file.
my $http_response = $upyun->response;
Returns latest response,it's an instance of HTTP::Response.
Raw response content body.
These methods indicate if the response was informational, successful, or an error. If the response code was 2xx code, is_success is true, else is_error is true.
The code is a 3 digit number that encode the overall outcome of the last HTTP response.
The message is a short human readable single line string that explains the last response code.
Internal, send signed request to server.
Private.
Much jobs to do.
handy client shell.
copy/move file under same bucket or between different bucket.
simple check file exists on remote ,no need to fetch its content,save bandwidth.
display/compare files checksum(MD5) local and remote.
streaming upload to save memory.
useful utility, like tar/untar to/from upyun on fly.
multi operation and performance requests in parallel.
code clean and refactory.
Night Sailer(Pan Fan) <nightsailer{at}gmail_dot_com>
Copyright (C) Pan Fan(nightsailer)
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Net::UpYun, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::UpYun
CPAN shell
perl -MCPAN -e shell install Net::UpYun
For more information on module installation, please visit the detailed CPAN module installation guide.