Home >Backend Development >PHP Tutorial >javascript - 七牛的上传凭证的uptoken应该怎么获取

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

WBOY
WBOYOriginal
2016-06-06 20:38:021598browse

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn