Module: Qiniu::RS::IO

Extended by:
Utils
Defined in:
lib/qiniu/rs/io.rb

Class Method Summary collapse

Methods included from Utils

crc32checksum, debug, encode_entry_uri, generate_qbox_signature, generate_query_string, http_request, is_response_ok?, response_error, safe_json_parse, send_request_with, upload_multipart_data, urlsafe_base64_decode, urlsafe_base64_encode

Class Method Details

.put_auth(expires_in = nil, callback_url = nil) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/qiniu/rs/io.rb', line 13

def put_auth(expires_in = nil, callback_url = nil)
  url = Config.settings[:io_host] + "/put-auth/"
  url += "#{expires_in}" if !expires_in.nil? && expires_in > 0
  if !callback_url.nil? && !callback_url.empty?
    encoded_callback_url = Utils.urlsafe_base64_encode(callback_url)
    url += "/callback/#{encoded_callback_url}"
  end
  Auth.request(url)
end

.put_file(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false) ⇒ Object



30
31
32
33
34
35
# File 'lib/qiniu/rs/io.rb', line 30

def put_file(local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, enable_crc32_check = false)
  action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check)
  url = Config.settings[:io_host] + action_params
  options = {:content_type => 'application/octet-stream'}
  Auth.request url, ::IO.read(local_file), options
end

.upload_file(url, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false) ⇒ Object



23
24
25
26
27
28
# File 'lib/qiniu/rs/io.rb', line 23

def upload_file(url, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false)
  action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check)
  callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.nil?
  callback_query_string = Utils.generate_query_string(callback_params)
  Utils.upload_multipart_data(url, local_file, action_params, callback_query_string)
end

.upload_with_token(uptoken, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false, rotate = nil) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/qiniu/rs/io.rb', line 37

def upload_with_token(uptoken, local_file, bucket, key = nil, mime_type = nil, custom_meta = nil, callback_params = nil, enable_crc32_check = false, rotate = nil)
  action_params = _generate_action_params(local_file, bucket, key, mime_type, custom_meta, enable_crc32_check, rotate)
  callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.nil?
  callback_query_string = Utils.generate_query_string(callback_params)
  url = Config.settings[:up_host] + '/upload'
  Utils.upload_multipart_data(url, local_file, action_params, callback_query_string, uptoken)
end