Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
Hi,
I am trying to upload the file to Dropbox using API v2 in PHP using curl. I am getting a 413 error response from the Dropbox server (Request entity too large).
So what is the limit to upload the file to Dropbox and Please let me know there is any limit on the paid account?
It sounds like you're using /2/files/upload. That endpoint does have a file size limit of 150 MB.
For larger files, you should use upload sessions instead.
This works the same way for both paid and free accounts.
Hi Greg,
Thanks for your response. please suggest how to use session with the curl in PHP.
An example of the same would be great because I am not able to implement it correctly after so many trials.
I changed my API URL: https://content.dropboxapi.com/2/files/upload_session/start
it gives "error in call to API function"
this is my header code
$headers = array('Authorization: Bearer ' . $token,
'Content-Type: application/octet-stream',
'Dropbox-API-Arg: ' .
json_encode(
array(
"path" => '/' . basename($destPath . $to_zip_folder),
"mode" => "add",
"autorename" => true,
"mute" => false
)
),
'Content-Type: application/octet-stream'
);
Thanks in advance.
vibh,
You seem to be doing things all yourself with curl. It might be easier for you to use some PHP bindings to the Dropbox API that someone else has made.
There doesn't seem to be an official Dropbox PHP binding, but this looks popular and sort of active on github: https://github.com/kunalvarma05/dropbox-php-sdk
You can see it uses upload sessions so that you can upload files larger than 100MB piece by piece://github.com/kunalvarma05/dropbox-php-sdk/blob/master/src/Dropbox/Dropbox.php#L780
To install it, full their instructions here. You might first have to install php composer to use this though, documentation for that is here.
If you're getting stuck on implementing an API just from the HTTP spec...I'd really recommend using an SDK since you'll likely just continue to have problems as you start using other Dropbox API features.
Hi,
Thanks for your response.
$api_url = 'https://content.dropboxapi.com/2/files/upload_session/start';
to above API 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, 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);
response === {"session_id": "AAAAAAAAAFAB2YI_TkrUgw"}
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'
);
$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, 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);
response === null
http_code === 200
$api2_url = 'https://content.dropboxapi.com/2/files/upload_session/finish';
to above 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'
);
$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
Please help.
Hi,
Thanks for your response. Below is my code what I am using.
$api_url = '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?
Please help.
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!