Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

grandcloud/sndacs-ruby

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sndacs library provides access to SNDA Cloud Storage.

bases on the s3 gem: github.com/qoobaa/s3

gem install sndacs
require "sndacs"

service = Sndacs::Service.new(:access_key_id => '...'
                              :secret_access_key => '...')
#=> #<Sndacs::Service:...>

or use even more flexible config style

require "sndacs"

# Setup global default configurations, see Sndacs::Config for more info
Config.access_key_id = '...'
Config.secret_access_key = '...'
Config.host = 'storage.grandcloud.cn'
Config.content_host = 'storage.sdcloud.cn'
Config.proxy = nil
Config.timeout = 60
Config.use_ssl = false
Config.chunk_size = 1048576
Config.debug = false
service = Sndacs::Service.new
#=> #<Sndacs::Service:...>
service.buckets
#=> [#<Sndacs::Bucket:first-bucket>,
#    #<Sndacs::Bucket:second-bucket>]

create a bucket to default location(huabei-1)

new_bucket = service.buckets.build("rubybucketdefault")
new_bucket.save

create a bucket to specify location,location can be ‘huadong-1’ or ‘huabei-1’ ,default to huabei-1

new_bucket = service.buckets.build("rubybuckethuadong-1")
new_bucket.save(:location=>"huadong-1")
first_bucket = service.buckets.find("first-bucket")
#=> #<Sndacs::Bucket:first-bucket>
first_bucket.location

set bucket public

bucket_policy = '{"Id":"b32c9be8-2414-d0ed-a19f-e0b3f37db5fc","Statement":[{"Sid":"public-get-object","Effect":"Allow","Action":"storage:GetObject","Resource":"srn:snda:storage:::'+first_bucket.name+'/*"}]}'
first_bucket.put_bucket_policy(bucket_policy)
bucket_policy = first_bucket.get_bucket_policy
first_bucket.delete_bucket_policy
first_bucket.objects
#=> [#<Sndacs::Object:/first-bucket/lenna.png>,
#    #<Sndacs::Object:/first-bucket/lenna_mini.png>]
object = first_bucket.objects.find("lenna.png")
#=> #<Sndacs::Object:/first-bucket/lenna.png>
object.content_type
#=> "image/png"
object.content
#=> "\x89PNG\r\n\x1A\n\x00\x00\x00\rIHDR\x00..."

Get a temporary url to the object that expires on the timestamp given.Defaults to 1hour expire time

object.temporary_url( Time.now + 60 )

Get a url to a public accessible object,the url only work when the object is public accessible

object.url( public_accessible = true)
object.destroy
#=> true
new_object = bucket.objects.build("bender.png")
#=> #<Sndacs::Object:/synergy-staging/bender.png>

new_object.content = open("bender.png")

new_object.save
#=> true

create an object with metadata

one_object = bucket.objects.build("put_object_test.txt")
=> #<Sndacs::Object:/beijing/put_object_test.txt>
one_object.content="labulabu"
one_object.save("x-snda-meta-mydata1"=>1,"x-snda-meta-mydata2"=>"mydata")
=> true
one_object.content_type
=> "text/plain"
one_object.metadata
=> [["x-snda-meta-mydata1", ["1"]], ["x-snda-meta-mydata2", ["mydata"]]]
one_object  # use object created above
=> #<Sndacs::Object:/beijing/put_object_test.txt>
dest_bucket = service.buckets.find(dbucket_name)
dest_object = dest_bucket.objects.build(dobject_name)
dest_object.copy(:bucket=>one_object.bucket.name,:key=>one_object.key,:if_none_match=>'"6372c977391b20d2887e2d7c46c079bf0"',:replace=>false,"x-snda-meta-testcopy"=>"hicopy")
=> true
dest_object.metadata
=> [["x-snda-meta-mydata1", ["1"]], ["x-snda-meta-mydata2", ["mydata"]]]
dest_object.content_type
=> "text/plain"
dest_object.etag
=> "6fafe919441e179042702236e3c56b5d"

Please note that new objects are created with “private” ACL by default.

Copyright © 2012 LI Daobing. See LICENSE for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.