Method: QcloudCos::ConvenientApi#public_url

Defined in:
lib/qcloud_cos/convenient_api.rb

#public_url(path, options = {}) ⇒ String

获取文件外网访问地址

Parameters:

  • path (String)

    指定文件路径

  • options (Hash) (defaults to: {})

    额外参数

Options Hash (options):

  • :bucket (String) — default: config.bucket_name

    指定当前 bucket, 默认是配置里面的 bucket

  • :expired (Integer) — default: 600

    指定有效期, 秒为单位

Returns:

  • (String)

    下载地址

Raises:

[View source]

93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/qcloud_cos/convenient_api.rb', line 93

def public_url(path, options = {})
  path = fixed_path(path)
  bucket = validates(path, options)

  result = stat(path, options)
  if result.key?('data') && result['data'].key?('access_url')
    expired = options['expired'] || PUBLIC_EXPIRED_SECONDS
    sign = authorization.sign(bucket, expired)
    "#{result['data']['access_url']}?sign=#{sign}"
  else
    fail FileNotExistError
  end
end