欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2024-02-03 17:22:52
...
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