在php无效的情况下上传新版本的box api文件方法
这是我用来发送请求的代码
$uploadfile =$_SESSION['uploadfile'];
$fileid =$_SESSION['fileid'];
$myuri='https://upload.box.com/api/2.0/files/'.$fileid.'/content';
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$_SESSION['usertoken']));
curl_setopt_array($curl2, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $myuri,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
filename => "@".$uploadfile
)
));
// Send the request & save response to $resp
$data = curl_exec($curl2);
$data = json_decode($data);
我从框中得到以下错误回复:
object(stdClass)#1 (7) { ["type"]=> string(5) "error" ["status"]=> int(400) ["code"]=> string(11) "bad_request" ["context_info"]=> object(stdClass)#2 (1) { ["errors"]=> array(1) { [0]=> object(stdClass)#3 (3) { ["reason"]=> string(17) "missing_parameter" ["name"]=> string(6) "parent" ["message"]=> string(20) "'parent' is required" } } } ["help_url"]=> string(38) "http://developers.box.com/docs/#errors" ["message"]=> string(11) "Bad Request" ["request_id"]=> string(23) "1638286030525d1c87c6a1e" }
根据他们的文档,我只需要我试图上传的文件的文件名和我试图覆盖它的文件的文件ID没有说要求父母我在这里缺少什么?这是一个错误还是文档错误?
可以在http://developers.box.com/docs/#files-upload-a-new-version-of-a-file
找到文档答案 0 :(得分:0)
我认为这个盒子文件很糟糕。如果它被列为文档中的参数,那么明智的话就是根据需要列出的。这是工作代码
$fileid = $_REQUEST["fileid"];
$uploadfile =$_SESSION['uploadfile'];
$myuri="https://api.box.com/2.0/files/".$fileid;
$curl = curl_init($myuri);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$_SESSION['usertoken']));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($curl);
curl_close($curl);
$data = json_decode($data);
//var_dump($data);
$etag =$data->etag;
date_default_timezone_set("UTC");
$timestamp = date(DATE_ATOM);
$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_HTTPHEADER, array('If-Match: '.$etag,'Authorization: Bearer '.$_SESSION['usertoken']));
curl_setopt_array($curl2, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => 'https://upload.box.com/api/2.0/files/'.$fileid.'/content',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
filename => "@".$uploadfile,
content_modified_at =>$timestamp
)
));
$data2 = curl_exec($curl2);
$data2 = json_decode($data2);