Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Storage API

p0deje edited this page · 9 revisions

Storage

Get information about user's storage.

GroupDocs::Storage.info!
#=> { total_space: "1024 MB", available_space: "1020 MB", document_credits: 5000, available_credits: 4964 }

Folders

Create new folder on server.

GroupDocs::Storage::Folder.create!('/folder')
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @id=1 @name="folder" @url="http://groupdocs.com">

or

folder = GroupDocs::Storage::Folder.new(name: 'Folder')
folder.create!
#=> #<GroupDocs::Storage::Folder:0x0000000171f432 @id=1 @name="Folder" @url="http://groupdocs.com">

List all folders and files in the root.

GroupDocs::Storage::Folder.list!
#=> [#<GroupDocs::Storage::Folder:0x0000000171f432 @id=1 @name="Folder1" @url="http://groupdocs.com">, #<GroupDocs::Storage::Folder:0x0000000171f478 @id=2 @name="Folder2" @url="http://groupdocs.com">]

List all folders and files in the specific folder.

GroupDocs::Storage::Folder.list!('/Folder1')
#=> [#<GroupDocs::Storage::Folder:0x0000000171f432 @id=1 @name="Folder1" @url="http://groupdocs.com">]

or

folder = GroupDocs::Storage::Folder.list!.first
folder.list!
#=> [#<GroupDocs::Storage::Folder:0x0000000171f432 @id=1 @name="Folder1" @url="http://groupdocs.com">]

Get the list of share users of folder

folder = GroupDocs::Storage::Folder.list!.first
folder.sharers!
#=> [#<GroupDocs::User:0x000000018b00c8 @nickname="test@test.com", @token="d787859010d33e6014bd53a278e1724f9f0f8331da2b7effbc148ec555fa38b8", @signed_up_on=44167-10-03 19:28:53 +0700, @id=57, @guid="08ad113e4a85a804", @primary_email="test@test.com">]

Set sharers of folder

folder = GroupDocs::Storage::Folder.list!.first
folder.sharers_set!(%w(friend_one@gmail.com friend_two@gmail.com))
#=> ['friend_one@gmail.com', 'friend_two@gmail.com']

Remove all sharers of folder

folder = GroupDocs::Storage::Folder.list!.first
folder.sharers_clear!

or

folder = GroupDocs::Storage::Folder.list!.first
folder.sharers = []

or

folder = GroupDocs::Storage::Folder.list!.first
folder.sharers = nil

Move folder contents to new folder.

folder = GroupDocs::Storage::Folder.list!.first
folder.move!('/Folder2')
#=> '/Folder2'

Rename folder.

folder = GroupDocs::Storage::Folder.list!.first
folder.rename!('Folder2')
#=> 'Folder2'

Copy folder with all contents to a new folder.

folder = GroupDocs::Storage::Folder.list!.first
folder.copy!('/Folder2')
#=> '/Folder2'

Delete folder.

folder = GroupDocs::Storage::Folder.list!.first
folder.delete!

Files

Upload file

GroupDocs::Storage::File.upload!('Documents/resume.pdf', name: 'cv.pdf')
#=> #<GroupDocs::Storage::File:0x0000000171f432 @id=123 @guid=uhfsa9dry29rhfodn @name="cv.pdf" @url="http://groupdocs.com">

Download file

file = GroupDocs::Storage::Folder.list!.last
file.download!('Documents')
#=> '/Documents/resume.pdf'

Move file.

file = GroupDocs::Storage::Folder.list!.last
file.move!('/Folder')
#=> #<GroupDocs::Storage::File:0x0000000171f432 @id=123 @guid=uhfsa9dry29rhfodn @name="resume.pdf" @url="http://groupdocs.com">

Rename file.

file = GroupDocs::Storage::Folder.list!.last
file.rename!('cv.pdf')
#=> #<GroupDocs::Storage::File:0x0000000171f432 @id=123 @guid=uhfsa9dry29rhfodn @name="cv.pdf" @url="http://groupdocs.com">

Copy file.

file = GroupDocs::Storage::Folder.list!.last
file.copy!('resume-backup.pdf')
#=> #<GroupDocs::Storage::File:0x0000000171f432 @id=123 @guid=uhfsa9dry29rhfodn @name="resume-bakcup.pdf" @url="http://groupdocs.com">

Compress file.

file = GroupDocs::Storage::Folder.list!.last
file.compress!
#=> #<GroupDocs::Storage::File:0x0000000171f432 @id=123 @guid=uhfsa9dry29rhfodn @name="resume.pdf.zip" @url="http://groupdocs.com">

Delete file.

file = GroupDocs::Storage::Folder.list!.last
file.delete!

Packages

Create package with several files

package = GroupDocs::Storage::Package.new do |package|
  package.name = 'resumes_package'
  package << GroupDocs::Storage::Folder.list![0]
  package << GroupDocs::Storage::Folder.list![1]
  package << GroupDocs::Storage::Folder.list![2]
end
package.create!
#=> 'http://api.groupdocs.com/shared/files/resumes_package.zip'
Something went wrong with that request. Please try again.