问题描述
服务器上用的是php,上传用的是form表单,流程是通过服务器获得uploadToken给html表单,然后上传,正常情况下不设置callbackUrl的时候是可以正常返回的,但是设置了之后就不返回了,直接返回一个Null.是不是七牛在设置异常回调地址后前端的访问就不回调了?
以下是代码
获得token
// 生成上传 Token
$auth = $this->getauth();
$bucket = 'demo';
$policy = array(
'callbackUrl' => 'http://120.27.44.143/notify',
'callbackBody' => json_encode($body),
);
$token = $auth->uploadToken($bucket, "demo", 3600, $policy);
// $token = $auth->uploadToken($bucket);
Response::showResult(Response::OK_CODE,'',$token,Response::JSON);
----
获得auth的方法
private function getauth(){
$accessKey = QiniuConst::AK;
$secretKey = QiniuConst::SK;
$auth = new Auth($accessKey, $secretKey);
return $auth;
}
表单上传
<form method="post" action="http://upload.qiniu.com/"
enctype="multipart/form-data">
<input name="key" value="null">
<input name="x:parentId" value="1044">
<input name="token" type="hidden" value="AhjeVFPALrhk1eEq7be60YN1jrQxGSsFOuRI2a_L:1gimtjK6aI--XA7TDJUAEpaJqhY=:eyJjYWxsYmFja1VybCI6Imh0dHA6XC9cLzEyMC4yNy40NC4xNDNcL25vdGlmeSIsImNhbGxiYWNrQm9keSI6IntcImNvZGVcIjoxMDAsXCJkYXRhXCI6XCJoYWhhXCJ9IiwicmV0dXJuQm9keSI6IntcImtleVwiOiAkKGtleSksXCJwYXJlbnRJZFwiOiQocGFyZW50SWQpfSIsInNjb3BlIjoiZGVtbzpkZW1vIiwiZGVhZGxpbmUiOjE0ODc1ODk4MjgsInVwSG9zdHMiOlsiaHR0cDpcL1wvdXAucWluaXUuY29tIiwiaHR0cDpcL1wvdXBsb2FkLnFpbml1LmNvbSIsIi1IIHVwLnFpbml1LmNvbSBodHRwOlwvXC8xODMuMTM2LjEzOS4xNiJdfQ==">
<input name="file" type="file" />
<input type="submit" value="Submit" />
</form>
找到问题了,如果设置了callback的话,就需要在异步回调中处理并返回结果,然后将结果以json的形式返回来就可以了