class GroupDocs::Storage::File

Constants

DOCUMENT_TYPES

Attributes

access[RW]

@attr [Symbol] access

adj_name=[RW]

@attr [String] name

created_on[RW]

@attr [Time] created_on

file_type[RW]

@attr [Symbol] file_type

guid[RW]

@attr [String] guid

id[RW]

@attr [Integer] id

known[RW]

@attr [Boolean] known

local_path[RW]

@attr [String] local_path

modified_on[RW]

@attr [Time] modified_on

name[RW]

@attr [String] name

path[RW]

@attr [String] path

size[RW]

@attr [Integer] size

thumbnail[RW]

@attr [String] thumbnail

type[RW]

@attr [Symbol] type

url[RW]

@attr [String] url

version[RW]

@attr [Integer] version

Public Class Methods

decompress!(filepath, options = {}, access = {}) click to toggle source

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
get_shared_file!(path, name, user_email, file_path) click to toggle source

Get shared file.

@param [String] path Path save new file which receive in response @param [String] name Name new file @param [String] file_path @param [String] user_email

# File lib/groupdocs/storage/file.rb, line 64
def self.get_shared_file!(path, name, user_email, file_path)
  response = Api::Request.new do |request|
    request[:access] = access
    request[:method] = :GET
    request[:path] = "/storage/shared/#{user_email}/#{file_path}"
  end.execute!

  filepath = "#{path}/#{name}"
  Object::File.open(filepath, 'wb') do |file|
    file.write(response)
  end

  filepath
end
upload!(filepath, options = {}, access = {}) click to toggle source

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
upload_google!(options = {}, access = {}) click to toggle source

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
upload_web!(url, access = {}) click to toggle source

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

compress!(access = {}) click to toggle source

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
copy!(path, options = {}, access = {}) click to toggle source

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
delete!(access = {}) click to toggle source

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
download!(path, access = {}) click to toggle source

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
move!(path, options = {}, access = {}) click to toggle source

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
move_to_trash!(access = {}) click to toggle source

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
rename!(name, access = {}) click to toggle source

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_to_trash!(path, access = {}) click to toggle source

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
to_document() click to toggle source

Converts file to GroupDocs::Document.

@return [GroupDocs::Document]

# File lib/groupdocs/storage/file.rb, line 408
def to_document
  Document.new(:file => self)
end
type=(type) click to toggle source

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
upload_cancel!(path, access = {}) click to toggle source
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