我想在apiv2中使用PHP curl在dropbox上上传更大的文件。 [英] I want to upload larger file on dropbox using PHP curl in apiv2.
问题描述
我想在APIv2中使用PHP curl将较大的文件上传到Dropbox。我编写了代码但是我收到的错误是status_code = 413(请求实体太大)。
我发布了我的代码。你的帮助对我很有帮助。
https://content.dropboxapi.com/2/files/upload_session/start';
我上面的代码是:
$ headers = array('授权:Bearer'。$ token,
'Content-Type:application / octet-stream',
'Dropbox-API-Arg:'。
json_encode(
array (
关闭=>假,
)
),
'内容类型:application / octet-stream'
);
$ ch = curl_init($ api_url);
curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers);
curl_setopt($ ch,CURLOPT_POST,true);
$ path = $ destPath。 $ to_zip_folder;
// echo $ path; die;
$ fp = fopen($ path,'rb');
$ filesize = filesize($ path);
curl_setopt($ ch,CURLOPT_POSTFIELDS,'');
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true );
curl_setopt($ ch,CURLOPT_VERBOSE,1); // debug
$ response = curl_exec($ ch);
$ http_code = curl_getinfo($ ch,CURLINFO_HTTP_CODE);
curl_close($ ch);
回复=== {session_id :AAAAAAAAAFXd8SqjQyOldQ}
http_code === 200
$ api1_url ='https://content.dropboxapi.com/2/files/upload_session/append_v2';
以上API我的代码是:
$ headers1 = array('授权:Bearer'。$ token,
'Content-Type:application / octet-stream',
'Dropbox-API-Arg:'。
json_encode(
数组(
cursor=> $ w,
close=> false ,
)
),
'内容类型:application / octet-stream'
);
// print_r($ headers1);死亡;
$ ch = curl_init($ api1_url);
curl_setopt($ ch,CURLOPT_HTTPHEADER,$ headers1);
curl_setopt($ ch,CURLOPT_POST,true);
$ path = $ destPath。 $ to_zip_folder;
// echo $ path; die;
$ fp = fopen($ path,'rb');
$ filesize = filesize($ path);
curl_setopt($ ch,CURLOPT_POSTFIELDS,'');
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true );
curl_setopt($ ch,CURLOPT_VERBOSE,1); // debug
$ response = curl_exec($ ch);
$ http_code = curl_getinfo($ ch,CURLINFO_HTTP_CODE);
curl_close($ ch);
回复=== null
http_code === 200
$ api2_url ='https://content.dropboxapi.com/2/files/upload_session/finish';
对于上面的API我的代码是:
$ headers2 = array('授权:Bearer'。$ token,
'内容类型: application / octet-stream',
'Dropbox-API-Arg:'。
json_encode(
array(
$ b) $ b
cursor=> $ w1,
commit=> $ q,
)
),
'内容类型:application / octet-stream'
);
// print_r($ headers2); die;
$ ch = curl_init($ api2_url);
curl_setop t($ ch,CURLOPT_HTTPHEADER,$ headers2);
curl_setopt($ ch,CURLOPT_POST,true);
$ path = $ destPath 。 $ to_zip_folder;
// echo $ path; die;
$ fp = fopen($ path,'rb');
$ filesize = filesize($ path);
curl_setopt($ ch,CURLOPT_POSTFIELDS,fread($ fp,$ filesize));
curl_setopt( $ ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ ch,CURLOPT_VERBOSE,1); // debug
$ response = curl_exec($ ch);
$ http_code = curl_getinfo($ ch,CURLINFO_HTTP_CODE);
curl_close($ ch);
http_code === 413
如果我使用
curl_setopt($ ch,CURLOPT_POSTFIELDS,fread($ fp,$ filesize));
然后status_code = 413.
如果我使用
curl_setopt($ ch,CURLOPT_POSTFIELDS,'');
然后它将保存0字节文件。
请建议这三种API应该是什么样的?
提前致谢。
我尝试过的事情:
我试过PHP Curl。我不明白是什么问题?
Hi,
I want to upload the larger file to Dropbox using PHP curl in APIv2. I have written the code but I am getting an error that is status_code = 413(request entity too large).
I am posting my code. Your help would be a great favor to me.
https://content.dropboxapi.com/2/files/upload_session/start';
To above my code is:
$headers = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"close"=>false,
)
),
'Content-Type: application/octet-stream'
);
$ch = curl_init($api_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
$path = $destPath . $to_zip_folder;
//echo $path;die;
$fp = fopen($path, 'rb');
$filesize = filesize($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
response === {"session_id": "AAAAAAAAAFXd8SqjQyOldQ"}
http_code === 200
$api1_url = 'https://content.dropboxapi.com/2/files/upload_session/append_v2';
To above API my code is:
$headers1 = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"cursor"=>$w,
"close" => false,
)
),
'Content-Type: application/octet-stream'
);
//print_r($headers1);die;
$ch = curl_init($api1_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers1);
curl_setopt($ch, CURLOPT_POST, true);
$path = $destPath . $to_zip_folder;
//echo $path;die;
$fp = fopen($path, 'rb');
$filesize = filesize($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
response === null
http_code === 200
$api2_url = 'https://content.dropboxapi.com/2/files/upload_session/finish';
To above API my code is:
$headers2 = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: ' .
json_encode(
array(
"cursor"=>$w1,
"commit"=>$q,
)
),
'Content-Type: application/octet-stream'
);
// print_r($headers2);die;
$ch = curl_init($api2_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers2);
curl_setopt($ch, CURLOPT_POST, true);
$path = $destPath . $to_zip_folder;
//echo $path;die;
$fp = fopen($path, 'rb');
$filesize = filesize($path);
curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp,$filesize));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, 1); // debug
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
http_code === 413
if I use
curl_setopt($ch, CURLOPT_POSTFIELDS, fread($fp,$filesize));
then status_code = 413.
if I use
curl_setopt($ch, CURLOPT_POSTFIELDS, '');
then it will save 0-byte file.
please suggest what curl should be for these three API?
Thanks in advance.
What I have tried:
I have tried PHP Curl. I am not understanding what is the problem?
推荐答案
headers = array('Authorization:Bearer'。
headers = array('Authorization: Bearer ' .
token,
'Content-Type:application / octet-stream',
'Dropbox-API-Arg:'。
json_encode(
数组(
关闭=> false,
)
),< br $>
'内容类型:application / octet-stream'
);
token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: '.
json_encode(
array(
"close"=>false,
)
),
'Content-Type: application/octet-stream'
);
ch = curl_init(
ch = curl_init(
这篇关于我想在apiv2中使用PHP curl在dropbox上上传更大的文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!