class GroupDocs::Storage::File
Constants
- DOCUMENT_TYPES
Attributes
@attr [Symbol] access
@attr [String] name
@attr [Time] created_on
@attr [Symbol] file_type
@attr [String] guid
@attr [Integer] id
@attr [Boolean] known
@attr [String] local_path
@attr [Time] modified_on
@attr [String] name
@attr [String] path
@attr [Integer] size
@attr [String] thumbnail
@attr [Symbol] type
@attr [String] url
@attr [Integer] version
Public Class Methods
Uploads and unzip as file.
@param [String] path @param [Hash] options @option description [String] @option archiveType [String] @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File]
# File lib/groupdocs/storage/file.rb, line 138 def self.decompress!(filepath, options = {}, access = {}) options[:path] ||= '' options[:name] ||= Object::File.basename(filepath) path = prepare_path("#{options[:path]}/#{options[:name]}") api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/decompress/#{path}/" request[:request_body] = Object::File.new(filepath, 'rb') end api.add_params(:archiveType => options[:archiveType]) if options[:archiveType] json = api.execute! json[:files].map do |file| File.new(file) end end
Uploads file to API server.
@example Upload file to root directory
GroupDocs::Storage::File.upload!('resume.pdf')
@example Upload file to specific directory
GroupDocs::Storage::File.upload!('resume.pdf', path: 'folder1')
@example Upload and rename file
GroupDocs::Storage::File.upload!('resume.pdf', name: 'cv.pdf')
@example Upload file with description
GroupDocs::Storage::File.upload!('resume.pdf', description: 'Resume')
@example Upload file with callback URL
GroupDocs::Storage::File.upload!('resume.pdf', callbackUrl: 'http://google.com')
@param [String] filepath Path to file to be uploaded @param [Hash] options @option options [String] path Folder
path to upload to @option options [String] name Name of file to be renamed @option options [String] :description File
description @option options [String] :callbackUrl will be called after file is uploaded
@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File]
# File lib/groupdocs/storage/file.rb, line 39 def self.upload!(filepath, options = {}, access = {}) options[:path] ||= '' options[:name] ||= Object::File.basename(filepath) path = prepare_path("#{options[:path]}/#{options[:name]}") api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/folders/#{path}" request[:request_body] = Object::File.new(filepath, 'rb') end api.add_params(:description => options[:description]) if options[:description] json = api.execute! Storage::File.new(json) end
Updated in release 2.2.0
Uploads google page as file.
@param [Hash] options @option url [String] @option description [String] @option accessToken [String] @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File]
# File lib/groupdocs/storage/file.rb, line 113 def self.upload_google!(options = {}, access = {}) api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/google/files/" end api.add_params(options) json = api.execute! Storage::File.new(json) end
Uploads web page as file.
@param [String] url @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File]
# File lib/groupdocs/storage/file.rb, line 88 def self.upload_web!(url, access = {}) api = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = '/storage/{{client_id}}/urls' end api.add_params(:url => url) json = api.execute! Storage::File.new(json) end
Public Instance Methods
Compresses file on server to given archive type.
@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File] Archive file
# File lib/groupdocs/storage/file.rb, line 346 def compress!(access = {}) json = Api::Request.new do |request| request[:access] = access request[:method] = :POST request[:path] = "/storage/{{client_id}}/files/#{id}/archive/zip" end.execute! # add filename for further file operations json[:name] = "#{name}.zip" Storage::File.new(json) end
Moves file to given path.
@param [String] path @param [Hash] options @option options [String] name @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File] Copied to file
# File lib/groupdocs/storage/file.rb, line 324 def copy!(path, options = {}, access = {}) options[:name] ||= name path = prepare_path("#{path}/#{options[:name]}") json = Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:headers] = { :'Groupdocs-Copy' => id } request[:path] = "/storage/{{client_id}}/files/#{path}" end.execute! Storage::File.new(json[:dst_file]) end
Deletes file from server.
@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key
# File lib/groupdocs/storage/file.rb, line 365 def delete!(access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :DELETE request[:path] = "/storage/{{client_id}}/files/#{guid}" end.execute! end
Downloads file to given path.
@param [String] path Directory to download file to @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [String] Path to downloaded file
# File lib/groupdocs/storage/file.rb, line 260 def download!(path, access = {}) response = Api::Request.new do |request| request[:access] = access request[:method] = :DOWNLOAD request[:path] = "/storage/{{client_id}}/files/#{guid}" end.execute! filepath = "#{path}/#{name}" Object::File.open(filepath, 'wb') do |file| file.write(response) end filepath end
Moves file to given path.
@param [String] path @param [Hash] options @option options [String] name @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File] Moved to file
# File lib/groupdocs/storage/file.rb, line 286 def move!(path, options = {}, access = {}) options[:name] ||= name path = prepare_path("#{path}/#{options[:name]}") json = Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:headers] = { :'Groupdocs-Move' => id } request[:path] = "/storage/{{client_id}}/files/#{path}" end.execute! Storage::File.new(json[:dst_file]) end
Moves file to trash on server.
@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key
# File lib/groupdocs/storage/file.rb, line 380 def move_to_trash!(access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :PUT request[:path] = "/storage/{{client_id}}/trash/#{path}/#{name}" end.execute! end
Renames file to new one.
@param [String] name New file name @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key @return [GroupDocs::Storage::File] Renamed file
# File lib/groupdocs/storage/file.rb, line 309 def rename!(name, access = {}) move!(path, { :name => name }, access) end
Restore file from trash on server.
@param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key
# File lib/groupdocs/storage/file.rb, line 395 def restore_to_trash!(path, access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :DELETE request[:path] = "/storage/{{client_id}}/trash/#{path}" end.execute! end
Converts file to GroupDocs::Document
.
@return [GroupDocs::Document]
# File lib/groupdocs/storage/file.rb, line 408 def to_document Document.new(:file => self) end
Updates type with machine-readable format.
@param [Symbol] type @raise [ArgumentError] if type is unknown
# File lib/groupdocs/storage/file.rb, line 197 def type=(type) if type.is_a?(Symbol) type = type.to_s.capitalize DOCUMENT_TYPES.include?(type) or raise ArgumentError, "Unknown type: #{type.inspect}" end @type = type end
Added in release 1.5.8
Cancel file upload
@param [String] path File
path (name) @param [Hash] access Access credentials @option access [String] :client_id @option access [String] :private_key
# File lib/groupdocs/storage/file.rb, line 422 def upload_cancel!(path, access = {}) Api::Request.new do |request| request[:access] = access request[:method] = :GET request[:path] = "/storage/{{client_id}}/cancelUpload/#{id}/#{path}" end.execute! end