Module: Qiniu::S3::IO

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

Class Method Summary collapse

Methods included from Utils

encode_entry_uri, generate_query_string, http_request, 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/s3/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(url, local_file, bucket = '', key = '', mime_type = '', custom_meta = '', callback_params = '') ⇒ Object

Raises:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/qiniu/s3/io.rb', line 23

def put_file(url, local_file, bucket = '', key = '', mime_type = '', custom_meta = '', callback_params = '')
  raise NoSuchFileError unless File.exist?(local_file)
  key = Digest::SHA1.hexdigest(local_file + Time.now.to_s) if key.empty?
  entry_uri = bucket + ':' + key
  if mime_type.empty?
    mime = MIME::Types.type_for local_file
    mime_type = mime.empty? ? 'application/octet-stream' : mime[0].content_type
  end
  action_params = '/rs-put/' + Utils.urlsafe_base64_encode(entry_uri) + '/mimeType/' + Utils.urlsafe_base64_encode(mime_type)
  action_params += '/meta/' + Utils.urlsafe_base64_encode(custom_meta) unless custom_meta.empty?
  callback_params = {:bucket => bucket, :key => key, :mime_type => mime_type} if callback_params.empty?
  callback_query_string = Utils.generate_query_string(callback_params)
  Utils.upload_multipart_data(url, local_file, action_params, callback_query_string)
end