首页 >后端开发 >php教程 >javascript - 七牛的上传凭证的uptoken应该怎么获取

javascript - 七牛的上传凭证的uptoken应该怎么获取

WBOY
WBOY原创
2016-06-06 20:38:021598浏览

scope = 'my-bucket:sunflower.jpg'
deadline = 1451491200
returnBody = '{
"name": $(fname),
"size": $(fsize),
"w": $(imageInfo.width),
"h": $(imageInfo.height),
"hash": $(etag)
}'
putPolicy = '{"scope":"my-bucket:sunflower.jpg","deadline":1451491200,"returnBody":"{\"name\":$(fname),\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height),\"hash\":$(etag)}"}'
encodedPutPolicy = urlsafe_base64_encode(putPolicy)
sign = hmac_sha1(encodedPutPolicy, "")
encodedSign = "wQ4ofysef1R7IKnrziqtomqyDvI="
uploadToken = AccessKey + ':' + encodedSign + ':' + encodedPutPolicy
我用html提交图片,上传到http://upload.qiniu.com/,后台用php,
我该怎么搭建后端,怎么通过ajax来获取uptoken,是在是看不懂这个api

回复内容:

scope = 'my-bucket:sunflower.jpg'
deadline = 1451491200
returnBody = '{
"name": $(fname),
"size": $(fsize),
"w": $(imageInfo.width),
"h": $(imageInfo.height),
"hash": $(etag)
}'
putPolicy = '{"scope":"my-bucket:sunflower.jpg","deadline":1451491200,"returnBody":"{\"name\":$(fname),\"size\":$(fsize),\"w\":$(imageInfo.width),\"h\":$(imageInfo.height),\"hash\":$(etag)}"}'
encodedPutPolicy = urlsafe_base64_encode(putPolicy)
sign = hmac_sha1(encodedPutPolicy, "")
encodedSign = "wQ4ofysef1R7IKnrziqtomqyDvI="
uploadToken = AccessKey + ':' + encodedSign + ':' + encodedPutPolicy
我用html提交图片,上传到http://upload.qiniu.com/,后台用php,
我该怎么搭建后端,怎么通过ajax来获取uptoken,是在是看不懂这个api

后台使用php的话,七牛的php-sdk中直接就给出了上传凭证的整个生成过程,https://github.com/qiniu/php-sdk/blob/v6/qiniu/rs.php#L67,另外你可以直接参考上传demo,方便你的理解,https://github.com/qiniu/php-sdk/blob/v6/demo/up.php

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn