七牛fetch api:
POST /fetch/<EncodedURL>/to/<EncodedEntryURI> HTTP/1.1
####请问Host指的是七牛绑定的域名吗?
Host: iovip.qbox.me
Content-Type: application/x-www-form-urlencoded
Authorization: QBox <AccessToken>
rails 代码如下:
from_url = Qiniu::Utils.urlsafe_base64_encode('https://sf-static.b0.upaiyun.com/v-5732db60/global/img/user-256.png')
to_url = Qiniu::Utils.encode_entry_uri('weixinpic',"xxx.png")
path = "/fetch/#{from_url}/to/#{to_url}"
signing_str = path+"\n"
encoded_sign = HMAC::SHA1.digest(signing_str,Qiniu::Config.settings[:secret_key])
encoded_sign_base64 = Qiniu::Utils.urlsafe_base64_encode(encoded_sign)
authorization = "QBox #{Qiniu::Config.settings[:access_key]}:#{encoded_sign_base64}"
####http://7xtx75.com1.z0.glb.clouddn.com 是七牛绑定的域名,不知是否为fetch api的Host?
result = HTTParty.post("http://7xtx75.com1.z0.glb.clouddn.com/fetch/#{from_url}/to/#{to_url}",
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded','Authorization' =>authorization } )
返回结果result:
{"error":"Document not found"}
from_url地址是存在的
请大家帮忙看一下,需要如何修改
正确修改后:
from_url = Qiniu::Utils.urlsafe_base64_encode('https://sf-static.b0.upaiyun.com/v-5732db60/global/img/user-256.png')
to_url = Qiniu::Utils.encode_entry_uri('weixinpic',"xxx.png")
path = "/fetch/#{from_url}/to/#{to_url}"
signing_str = path+"\n"
access_token = Qiniu::Auth.generate_acctoken(path)
authorization = "QBox #{access_token}"
host = 'iovip.qbox.me'
result = HTTParty.post("http://#{host}/fetch/#{from_url}/to/#{to_url}",
:headers => { 'Content-Type' => 'application/x-www-form-urlencoded','Authorization' =>authorization } )
赞!已收藏,有空测试下