QiNiuUploadTokenPutPolicyModel putPolicy = new QiNiuUploadTokenPutPolicyModel();
putPolicy.setScope(QiNiuConfig.QINIU_BUCKET);
putPolicy.setDeadline(CommonUtil.getTimeStamp() + 3600 * 1000);
ReturnBody returnBody=new ReturnBody();
returnBody.setFname("$(fname)");
returnBody.setFsize("$(fsize)");
returnBody.setW("$(imageInfo.width)");
returnBody.setH("$(imageInfo.height)");
returnBody.setEtag("$(etag)");
putPolicy.setReturnBody(returnBody);
String putPolicyJsonStr = JSON.toJSONString(putPolicy);
String encodedPutPolicy = UrlSafeBase64.encodeToString(putPolicyJsonStr);
String signature = "";
try {
signature = HMACSHA1.getSignature(encodedPutPolicy, QiNiuConfig.QINIU_SECRET_KEY);
} catch (Exception e) {
e.printStackTrace();
}
String encodedSign = UrlSafeBase64.encodeToString(signature);
String uploadToken = QiNiuConfig.QINIU_ACCESS_KEY + ':' + encodedSign + ':' + encodedPutPolicy;
请问这样生成是哪里不对吗?一直返回401
有几点疑问:
1.deadline ,在七牛空间生成文件的校验时间,这是时间过期有什么问题,是这个token就不能用了,要重新生成一个,也就是app要重新获取token吗
2.encodedPutPolicy = urlsafe_base64_encode(putPolicy) 这里的urlsafe_base64_encode我直接用七牛给的UrlSafeBase64.encodeToString这样对吗
3.sign = hmac_sha1(encodedPutPolicy, "<SecretKey>") 这个hmac_sha1工具类有吗?还是要自已写工具类?
4.
Auth auth = Auth.create(Constants.QINIU_ACCESS_KEY, Constants.QINIU_SECRET_KEY);
String token = auth.uploadToken(Constants.QINIU_BUCKET);
这个是什么作用?
1,是token过期了就必须重新获取token
2,你参考下这个博客
http://blog.csdn.net/netdxy/article/deta...